asterisk / ari-py

Library for accessing the Asterisk REST Interface
Other
151 stars 106 forks source link

ari-py does not work with requests > 2.0.1 and websocket-client > 0.12.0 #3

Closed thmcmahon closed 10 years ago

thmcmahon commented 10 years ago

In a fresh virtual environment using the default versions that pip installs of requests and websocket-client, the websocket fails to connect and returns the following error:

Traceback (most recent call last):
  File "example.py", line 25, in <module>
    client.run(apps="hello")
  File "/private/tmp/goo/env/lib/python2.7/site-packages/ari/client.py", line 115, in run
    self.__run(ws)
  File "/private/tmp/goo/env/lib/python2.7/site-packages/ari/client.py", line 88, in __run
    msg_json = json.loads(msg_str)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Output of pip freeze that fails

ari==0.1.1
backports.ssl-match-hostname==3.4.0.2
requests==2.3.0
six==1.7.2
swaggerpy==0.2.0
websocket-client==0.15.0
wsgiref==0.1.2
matt-jordan commented 10 years ago

So this issue is caused by the following code in request's PreparedRequest prepare method:

    # Don't do any URL preparation for oddball schemes
    if ':' in url and not url.lower().startswith('http'):
        self.url = url
        return

Since what we're attempting to build is a websocket connection (which has the scheme 'ws'), the parameters we pass to be prepared on the URL are getting dropped, and the URL is being returned without the query parameters.

We can work around this in swagger-py; I'll make a pull request there.

matt-jordan commented 10 years ago

Pull request on swagger-py should fix this issue:

https://github.com/digium/swagger-py/pull/5