Giter Club home page Giter Club logo

pyrabbit's Introduction

image

PyRabbit

pyrabbit is a module to make it easy to interface w/ RabbitMQ's HTTP Management API. It's tested against RabbitMQ 3.2.4 using Python 2.6-3.4. It has a pretty solid set of tests, and I use tox to test across Python versions.

PyRabbit is on PyPI, which makes it installable using pip or easy_install.

See the documentation at http://pyrabbit.readthedocs.org

Please send pull requests! Pyrabbit doesn't yet provide 100% coverage of the exposed RabbitMQ API, so dig in!

pyrabbit's People

Contributors

azumafuji avatar bkjones avatar cce avatar davidszotten avatar dzen avatar grunskis avatar inviscid avatar julienr avatar mattwilliamson avatar niedbalski avatar spil-sean avatar xmm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyrabbit's Issues

print in http

Can you remove the Print in http.py on line 101. I dont want that information in my console

API does not have exchange to exchange binding

ie.
/api/bindings/[VHOST]/e/[SourceExchange]/e/[TargetExchange]
JSON
{"vhost":"vhostname","source":"SourceExchange","destination_type":"e","destination":"TargetExchange","routing_key":"","arguments":{}}

Printing api URL disturbs target application

Method HTTPClient.do_call() (http.py, line 101) unconditionally echoes url. I use pyrabbit in an agent which catches and parses stdout. Echoed url causes error since is unexpected by the agent.

I see two possible solutions:

  1. The url is a debug message and thus it shall be removed.
  2. The url printing is useful somehow. Then the client class shall have option silent=False. If set to true, the url won't be echoed.

set_vhost_permissions raises NetworkError

I'm using pyrabbit version 1.1.0 with RabbitMQ-3.6.0

Below is the python code I have written using pyrabbit

from pyrabbit.api import Client
cl = Client('localhost:15672', 'guest', 'guest')
print cl.is_alive()
cl.create_vhost('example_vhost')
print cl.get_vhost_names()
print cl.get_vhost_permissions('example_vhost')
cl.set_vhost_permissions('example_vhost', 'guest', '.', '.', '.*')

The output of script shows a NetworkError as shown below:

True
[u'/', u'example_vhost']
None
Traceback (most recent call last):
File "C:\Gayatri\learning\test_pyrabbit.py", line 14, in
cl.set_vhost_permissions('example_vhost', 'guest', '.', '.', '.*')
File "C:\Python27\lib\site-packages\pyrabbit-1.1.0-py2.7.egg\pyrabbit\api.py",
line 345, in set_vhost_permissions
headers=Client.json_headers)
File "C:\Python27\lib\site-packages\pyrabbit-1.1.0-py2.7.egg\pyrabbit\http.py"
, line 111, in do_call
raise NetworkError("Error: %s %s" % (type(out), out))
pyrabbit.http.NetworkError: Error: <class 'socket.error'> [Errno 10053] An estab
lished connection was aborted by the software in your host machine

Any help to resolve this issue?

Thanks in Advance,
Gayatri

documentation error: httplib2.ServerNotFoundError: Unable to find the server at http

I believe in docs/index.rst line

cl = Client('http://localhost:55672/api', 'guest', 'guest')

should be

cl = Client('localhost:55672', 'guest', 'guest')

While copying example code, I first got:

root@2b2e772eeff1:/code# ./sender-http.py 
http://http:/rabbitmq:15672/api/api/exchanges/myvh/amq.default/publish
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py", line 1187, in _conn_request
    conn.connect()
  File "/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py", line 918, in connect
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pyrabbit/http.py", line 106, in do_call
    headers)
  File "/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py", line 1514, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py", line 1264, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py", line 1194, in _conn_request
    raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at http

And string http://http:/rabbitmq:15672/api/api/exchanges/myvh/amq.default/publish has obvious errors.

Problems with symbol "+"

Hi,
I found an issue when using the api method get_queue. It does not handle properly the symbol "+" and then, a query like get_queue("/", "a+b") fails.
My workaround is to do:
get_queue("/", re.sub(re.escape("+"), "%2B", "a+b"))
which is not needed for other special symbols.
Thanks!

Creating queue with 'auto_delete' also requires 'durable' and 'node' to be specified

c = Client(...)
c.create_queue(queue_name, '/', node='s-rabbit3', auto_delete='true', durable='true')

The above code runs fine, but if you take out any 1 or 2 of the kwargs (node/auto_delete/durable), an exception will be raised:

In [35]: c.create_queue(queue_name, '/', node='s-rabbit3', auto_delete='true')
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-35-07fe5a3f45ec> in <module>()
----> 1 c.create_queue(queue_name, '/', node='s-rabbit3', auto_delete='true')

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyrabbit/api.pyc in create_queue(self, name, vhost, auto_delete, durable, arguments, node)
    548                                  'PUT',
    549                                  body,
--> 550                                  headers=Client.json_headers)
    551
    552     def delete_queue(self, vhost, qname):

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyrabbit/http.pyc in do_call(self, path, reqtype, body, headers)
    103         # 'success' HTTP status codes are 200-206
    104         if resp.status < 200 or resp.status > 206:
--> 105             raise HTTPError(content, resp.status, resp.reason, path, body)
    106         else:
    107             if content:

HTTPError: 400 - Bad Request ([u'not_boolean', None]) (queues/%2F/reputation.workers.notification_worker.NotificationWorker) ('{"node": "s-rabbit3", "auto_delete": "true", "durable": null}')

response not JSON format

screenshot from 2013-10-17 17 3a05 3a11

I use a regular connection
Client('localhost:55672', 'guest', 'guest')

when i try to make a get_queue('/', queue-name) and the queue does not exist, it throws an error that is not handle correctly since it is not in JSON format.

set_vhost_permissions in docker container

When I try to set permissions and run script with set_vhost_permissions inside docker container, it is always raise BrokenPipeError. But if I run it without docker everything fine.

Other methods (like create_vhost/delete_vhost) works fine in docker container.

New release

How about new release?
Master branch contain a lot if fixes, but last release was in 2014 :)

changelog/release notes

Thanks for getting the new release out!

What do you think about starting a change log/release notes document with an overview of changes since the previous release? Would be a big help and much easier than trying to diff commit logs

Malformed urls in Windows environment

Pyrabbit generates malformed urls to the administrative api when used in a Windows environment. Each request will receive the expected response of 'Not Found'.

The issue is caused by using os.path.join to construct urls. See pyrabbit.http.do_call.

Deleting binding does not work if routing-key contains hash

If you have a binding using '#' as the routing key, invoking delete_binding with '#' will not work.

The DELETE http call is being made without properly encoding the '#' in the URL, resulting in a 405 error.

A workaround now is to manually url-encode the routing key ('%23') in the delete_binding() call

Thread safety

Hello,

when i try to run several RabbitMQ api requests concurrently with threads, i get strange "socket timeout" errors from pyrabbit. If I run the requests in sequence, no error.

I suppose the source cause lies in httplib2, which is probably not thread-safe.

Could you provide a 'requests' (http://docs.python-requests.org/) or urllib3 (https://urllib3.readthedocs.org/) backoffice instead ?

Regards,
Stephane

Breaking change?

So far I've been using the pypi version of pyrabbit, but we only had http endpoints.

I have an https endpoint to reach now, and I see that a PR was merged to this effect; so I pip-installed the current git revision and was able to use https.

However I had to specify the /api/ part of the path - looks like pyrabbit doesn't include this part of the path anymore. Previously I was able to create a client by specifying a server/port like this: myserver.mydomain.com:15672. This is no longer possible, but it starts working again with myserver.mydomain.com:15672/api/.

Is this an expected change?

Makes get queue size supports return only needed columns

The HTTP endpoint returns a lot of fields not needed which increases the payload.
RabbitMQ supports this using the columns parameter (as described here):
https://rawcdn.githack.com/rabbitmq/rabbitmq-server/v3.8.16/deps/rabbitmq_management/priv/www/api/index.html

You can also restrict what information is returned per item with the columns parameter. This is a comma-separated list of subfields separated by dots.

It would be great if pyrabbit support it! ❤️

get_messages now requires 'ackmode' on request

get_messages shows an error when trying it with the latest rabbitMQ, missing key 'ackmode'
When using the web browser GUI, there is a field called "Ack mode" for getting messages from a queue, upon further inspection these are the values:

<select name="ackmode">
                <option value="ack_requeue_true" selected="">Nack message requeue true</option>
                <option value="ack_requeue_false">Automatic ack</option>
                <option value="reject_requeue_true">Reject requeue true</option>
                <option value="reject_requeue_false">Reject requeue false</option>
</select>

I added it to my local pyrabbit package and it works :)

def get_messages(self, vhost, qname, count=1,
                     requeue=False, truncate=None, encoding='auto', ackmode='ack_requeue_false'):
...
base_body = {'count': count, 'requeue': requeue, 'encoding': encoding, 'ackmode': ackmode}

Decoding fails in python 3.3

Python 3.3.4
Pyrabbit 1.0.1
Httlib2 0.9

The following exception is thrown with an api call such as is_alive()

  ...
  File "C:\Python33\lib\site-packages\pyrabbit\api.py", line 48, in wrapper
    if self.has_admin_rights:
  File "C:\Python33\lib\site-packages\pyrabbit\api.py", line 175, in has_admin_rights
    whoami = self.get_whoami()
  File "C:\Python33\lib\site-packages\pyrabbit\api.py", line 161, in get_whoami
    whoami = self.http.do_call(path, 'GET')
  File "C:\Python33\lib\site-packages\pyrabbit\http.py", line 108, in do_call
    content = self.decode_json_content(content)
  File "C:\Python33\lib\site-packages\pyrabbit\http.py", line 75, in decode_json_content
    py_ct = json.loads(content)
  File "C:\Python33\lib\json\__init__.py", line 316, in loads
    return _default_decoder.decode(s)
  File "C:\Python33\lib\json\decoder.py", line 351, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object

Can't connect, whoami fails?

Hey there, thanks so much for releasing/maintaining this @bkjones !

I'm having a bit of trouble using this:

Client('localhost:5672', 'guest', 'guest').get_users()

I believe that's the proper way to initialize a connection? Based on the printed url, it seems to be right.. when I go there in my browser I get AMQP back from rabbitmq server.

In [15]: Client('localhost:5672', 'guest', 'guest').get_users()
http://localhost:5672/api/whoami
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-663fd0826ea7> in <module>()
----> 1 Client('localhost:5672', 'guest', 'guest').get_users()

/Users/eric/.virtualenvs/codalab-competitions/lib/python2.7/site-packages/pyrabbit/api.pyc in wrapper(self, *args, **kwargs)
     46 
     47         """
---> 48         if self.has_admin_rights:
     49             return fun(self, *args, **kwargs)
     50         else:

/Users/eric/.virtualenvs/codalab-competitions/lib/python2.7/site-packages/pyrabbit/api.pyc in has_admin_rights(self)
    177         if self.is_admin is None:
    178             whoami = self.get_whoami()
--> 179             self.is_admin = whoami.get('tags', '') == 'administrator'
    180 
    181         return self.is_admin

AttributeError: 'NoneType' object has no attribute 'get'

add get_node (node details)

It will collect statistics for each node of the cluster (or single node, if there is no cluster).
And so the same memory usage statistics (memory|binary)

add to api.py:

urls = {
            'nodes_by_name_memory': 'nodes/%s?memory=true',
            'nodes_by_name_binary': 'nodes/%s?binary=true',
            'nodes_by_name': 'nodes/%s',
#########################################


    def get_node(self, nodename, opt=None):
        """
        Get a single node, which requires nodename and optional memory or binary for memory statistic.

        :param string nodename: An individual node in the RabbitMQ cluster (even if there is no cluster).
        :param string opt: memory or binary.
            memory - to get memory statistics (it adds to the URL "?memory=true")
            binary - to get a breakdown of binary memory use  (it adds to the URL "?binary=true")
        :returns: A dictionary of queue properties.
        :rtype: dict

        """
        nodename = quote(nodename, '')
        if opt == 'memory':
            path = Client.urls['nodes_by_name_memory'] % (nodename)
        elif opt == 'binary':
            path = Client.urls['nodes_by_name_binary'] % (nodename)
        else:
            path = Client.urls['nodes_by_name'] % (nodename)

        queue = self.http.do_call(path, 'GET')
        return queue

Thank you!
Sorry for my english

Rights management doesn't work well with vhosts

I am using this library with CloudAMQP https://www.cloudamqp.com/ which gives me access to a single vhost.
I do not have administrator tags, but I have management and policymaker. Since @needs_admin_privs only checks for admin, it forbids me from calling Client.is_alive on my vhost even though I am allowed to do so (the call succeed with curl).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.