Im working on a little project that running rabbitmq with python, I need a way to access the management api and pull stats, jobs, etc. I have tried using pyRabbit, but doen't appear to be working unsure why, hoping better programmers might know? Below I was just following the basic tutorial and readme to perform the very basic task. My server is up, I'm able to connect outside of python and pyrabbit fine. I have installed off the dependencies with no luck, at least I think. Also open to other suggestions for just getting queue size, queues, active clients etc outside of pyRabbit.
'Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\user>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import nose
import httplib2
import mock
from pyrabbit.api import Client
import pyrabbit
cl = Client('my.ip.com:15672', 'guest', 'guest')
cl.is_alive()
No JSON object could be decoded - (Not found.) ()
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\pyrabbit\api.py", line 48, in wrapper if self.has_admin_rights:
File "C:\Python27\lib\site-packages\pyrabbit\api.py", line 175, in has_admin_right whoami = self.get_whoami()
File "C:\Python27\lib\site-packages\pyrabbit\api.py", line 161, in get_whoami whoami = self.http.do_call(path, 'GET')
File "C:\Python27\lib\site-packages\pyrabbit\http.py", line 112, in do_call raise HTTPError(content, resp.status, resp.reason, path, body)
pyrabbit.http.HTTPError: 404 - Object Not Found (None) (whoami) (None)'
I was never able to solve this. But, this forced me to learn what json is, I used simplejson along with httplib2 and it worked like a charm...
This might be a rabbitmq configuration problem: as it is written here: https://www.rabbitmq.com/access-control.html, "guest" user can only connect via localhost:
By default, the guest user is prohibited from connecting to the broker remotely; it can only connect over a loopback interface (i.e. localhost). This applies both to AMQP and to any other protocols enabled via plugins. Any other users you create will not (by default) be restricted in this way.
This is configured via the loopback_users item in the configuration file.
If you wish to allow the guest user to connect from a remote host, you should set the loopback_users configuration item to []. A complete >rabbitmq.config which does this would look like:
[{rabbit, [{loopback_users, []}]}].
Related
I'm running an app engine application in a virtual environment on windows 7 64bit, python 2.7.9 x64.
Here's the stacktrace:
p_system = platform.system()
File "C:\Python27\lib\platform.py", line 1310, in system
return uname()[0]
File "C:\Python27\lib\platform.py", line 1206, in uname
release,version,csd,ptype = win32_ver()
File "C:\Python27\lib\platform.py", line 597, in win32_ver
import _winreg
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\sandbox.py", line 945, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named _winreg
However, it works just fine from cli (outside venv):
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Admin>python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _winreg
>>> import platform
>>> platform.system()
'Windows'
>>>
Why does this happen? What can I do to fix this?
Module _winreg, as the docs say, exists to "expose the Windows registry API to Python".
App Engine does not supply a "Windows registry API" (nor any other Windows-specific API). Therefore, its sandbox blocks attempts to import the module -- note, at the end of your stack trace, that the exception is deliberately raised in module sandbox.py of the App Engine SDK.
Python's "virtual env" plays no part here -- it's all about App Engine.
Please clarify what task you're trying to accomplish with _winreg once your GAE app is deployed -- assume it's deployed to Linux servers (although the GAE runtime doesn't supply Linux-specific APIs either:-), so there is no Windows Registry API anywhere in the neighborhood...
The workaround provided by Google, until a fix is implemented, is as follows:
Go to: <sdk_root>\google\appengine\tools\devappserver2\python\sandbox.py
Find the definition of _WHITE_LIST_C_MODULES = [xxx]
Add the following two lines to the list:
'_winreg',
'_ctypes',
If this does not succeed, run python -m pip install google-cloud
I think that the problem is that GAE is not aware that you are in development mode, I suppose because the SERVER_SOFTWARE variable is set to something not starting with "Dev".
If you execute the following code (before calling any GAE library) it should fix the issue:
import os
os.environ['SERVER_SOFTWARE'] = 'Dev'
Note: Make sure this code is removed before going to production.
I had this problem a few days ago.
As said above, the GAE sandbox on Windows blocks some routines or libraries, even built-in one, because it is developed to Unix-like platform.
I opened an issue to Google Team and they passed a workaround:
https://issuetracker.google.com/issues/38290292
That workaround worked well.
I am trying to resolve some dependencies for the MYSQL connector for Python on Angstrom.
From the command line I get the following error:
Python 2.6.6 (r266:84292, Feb 25 2011, 16:50:01)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named io
I thought that IO was a base-level module. It appears to be up-to-date:
# opkg install python-core
Package python-core (2.6.6-ml12.2.6) installed in root is up to date.
Shouldn't IO be available by default, and what can I do to resolve this issue?
Thanks to Padraic Cunningham who lead me on the path to a solution.
I found that several files, including io.py were missing from the install. Building the Angstrom for the Beagleboard (XM) image from the Angstrom website did not include these files (or subsequent modifications I made deleted them?). I rebuilt Python, keeping the identical version, from the Python source.
I had to then rebuild the MySQL connector (from MySql/Oracle). (All my other modules including OpenCV continued to work without issue)
This worked and I am now able to query the database.
One additional note. Once all the dependencies were resolved, I still could not connect to the database. The problem was that the MySQL connector was assuming a TCP/IP connection rather than file based socket. So I had to add the following to the connection string:
unix_socket="/tmp/mysql.sock"
Such that the full connection string looked like this:
cnx = mysql.connector.connect(user='username', password='password', host='localhost', database='dbname', raise_on_warnings=True, unix_socket="/tmp/mysql.sock")
I am trying to install python. Or actually, have installed and deinstalled it a few times now. I am using pythonxy with the spyder IDE (i am used to matlab is why i want to use spyder). The 3.3.2 python would not even start with spyder on my win8 machine, so now I have the 2.7 version installed.
Spyder starts up now, but upon startup I get `'import sitecustomize' failed? in my console and python wont execute any commands I enter. After the error the startupscript keeps on going forever without doing anything and I cant do anything either anymore. The error tells me to start python with -v appendix, output below.
I have googled this error which gave me two possible solutions:
i should edit python.rb
https://github.com/mxcl/homebrew/commit/10ba101c323f98118b427f291e15abc5b3732991
or i should apply this (attachment in last post there) to sitecustomize
https://code.google.com/p/spyderlib/issues/detail?id=771
Applying the diff file did not help and as mata explains below the .rb file is used during install, so not applicable to my problem.
So my question: Does anybody know how to fix this bug from experience?
The error:
'import sitecustomize' failed; use -v for traceback
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
The traceback:
C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc matches C:\Python27\lib\site-packages\spyderlib\pil_patch.py
import spyderlib.pil_patch # precompiled from C:\Python27\lib\site-packages\spyderlib\pil_patch.pyc
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 498, in execsitecustomize
import sitecustomize
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 174, in <module>
os.environ["SPYDER_AR_STATE"].lower() == "true")
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\monitor.py", line 146, in __init__
self.n_request.connect( (host, notification_port) )
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(Spyder dev here) I'm almost sure your problem is because of a firewall issue. It seems your firewall is too strict and it's blocking all attempts to try to open a port for our purposes.
To avoid blocking the full application while evaluating stuff, we run our python interpreter on a different process than the one Spyder runs on. We communicate with that process using a simple sockets protocol, which opens a new port on your machine and sends data back and forth between the console and Spyder through that port.
That's also the reason why you are not seeing the error on a regular python interpreter: because it doesn't need to open a port to run.
Following Carlos Cordoba's answer, I did the following (using Ubuntu 15.10):
1-) Disabled the firewall
sudo ufw disable
2-) Reset spyder and applied default settings:
spyder --reset
spyder --default
3-) Ran Spyder again
spyder
4-) Enabled the firewall
sudo ufw enable
And it is working normally now.
After fumbling with the firewall settings, I couldn't find any that would make spyder work.
Some runs would work, others would not, with the exact same configuration.
I'd rule out the firewall for now.
I noticed that the port that sitecustomize attempts to connect to is not listening.
Setting SPYDER_DEBUG=True before launching spyder gives more details:
Traceback (most recent call last):
File "P:\Python33\lib\threading.py", line 637, in _bootstrap_inner
self.run()
File "P:\Python33\lib\site-packages\spyderlib\widgets\externalshell\introspection.py", line 64, in run
sock.bind( ("127.0.0.1", self.port) )
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions`
I did a dirty hack by replacing the line:
sock.bind( ("127.0.0.1", self.port) )
by the following:
for loopCount in range(10, -1, -1):
try:
sock.bind( ("127.0.0.1", self.port) )
break
except OSError:
if DEBUG:
logging.debug('Notification server: Bind on port %d failed...' % (self.port))
if not loopCount:
raise
import time
time.sleep(1)
It seems to work, but this may be more luck than anything else...
Versions:
Spyder 2.3.0dev1
python 3.3.2 (64 bit)
I had this same problem. worked on it for months...
the spyder from from the EPEL library for Redhat 7 (Scientific Linux).
Finally figured out I needed a extra package that was not set as a requirement. python-matplotlib
After adding that python package all my problems went away!
Arrrggghhhhh.......!!!!!
I'm trying to write data to the system log on Windows 7 using Pythons (2.7) logging.handlers.NTEventLogHandler. This does not work as there is apparently some registry access being denied. The software will be run without any special access rights. Is there any way to make this work?
Here is the exception I get:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> from logging import handlers
>>> syslog = handlers.NTEventLogHandler("Something")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\logging\handlers.py", line 917, in __init__
self._welu.AddSourceToRegistry(appname, dllname, logtype)
File "c:\Python27\lib\site-packages\win32\lib\win32evtlogutil.py", line 35, in
AddSourceToRegistry
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, app
Name))
pywintypes.error: (5, 'RegCreateKey', 'Access is denied.')
"Win32 Extensions for Python" is required to use sysLog on Windows. Are you sure that you have installed it? [1]
From the docs [2]:
The NTEventLogHandler class, located in the logging.handlers module, supports sending logging messages to a local Windows NT, Windows 2000 or Windows XP event log. Before you can use it, you need Mark Hammond’s Win32 extensions for Python installed.
[1] http://sourceforge.net/projects/pywin32/
[2] http://docs.python.org/2/library/logging.handlers.html
The answer in my case was to adjust the permissions in regedit for my account. In my case, logging to the Application Event Log, I had to add the Full Control permission to
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\Application
Setting just the Read permission did not work as this was already in place with the Authorized Users ACE. Also, the permission has to remain set for each execution (it isn't just a one time setting).
Alternately, you will avoid this error if you can just run your code as Administrator since the Administrators group already has Full Control over these keys.
My app needs a backup system and remote administration so I disabled the federated login for easier remote_api access. Now I can log in but I can't import my module:
montao$ python ./remote_api_shell.py -s montaoproject.appspot.com
Email: niklasro
Password:
App Engine remote_api shell
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2]
The db, users, urlfetch, and memcache modules are imported.
s~montaoproject> import i18n
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named i18n
s~montaoproject>
Could you tell me how to run some simple remote api commands? I could run the backup system and connect via /_ah/remote.api with python 2.7 so my setup seems correct and I might just need clearer understanding how to use the remote_api.
Update
This works but it seems to use the django 0.96:
ubuntu#ubuntu:/media/Lexar/montao$ PYTHONPATH=./montaoproject python ./remote_api_shell.py -s montaoproject.appspot.com
App Engine remote_api shell
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2]
The db, users, urlfetch, and memcache modules are imported.
s~montaoproject> import i18n
WARNING:root:You are using the default Django version (0.96). The default Django version will change in an App Engine release in the near future. Please call use_library() to explicitly select a Django version. For more information see http://code.google.com/appengine/docs/python/tools/libraries.html#Django
s~montaoproject>
Prefix your command with PYTHONPATH=. (or replace . with the directory your app is in). Without telling Python where it can find modules, it doesn't know where to look, and the current directory isn't part of the path by default.