Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to use json parameter breaks on request < 2.4.2 #88

Closed
andrewsomething opened this issue Feb 4, 2015 · 9 comments
Closed

Change to use json parameter breaks on request < 2.4.2 #88

andrewsomething opened this issue Feb 4, 2015 · 9 comments
Labels

Comments

@andrewsomething
Copy link
Contributor

The json parameter wasn't added to requests until version 2.4.2 So python-digitalocean is currently broken on systems with older versions like Ubuntu 14.04:

$ apt-cache policy python-requests
python-requests:
  Installed: 2.2.1-1ubuntu0.1
  Candidate: 2.2.1-1ubuntu0.1
  Version table:
 *** 2.2.1-1ubuntu0.1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
        100 /var/lib/dpkg/status
     2.2.1-1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
======================================================================
ERROR: test_take_snapshot_action (digitalocean.tests.test_droplet.TestDroplet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<string>", line 2, in _wrapper_
  File "/usr/lib/python2.7/dist-packages/responses.py", line 167, in wrapped
    return func(*args, **kwargs)
  File "/home/asb/projects/python-digitalocean/digitalocean/tests/test_droplet.py", line 338, in test_take_snapshot_action
    response = self.droplet.take_snapshot("New Snapshot", return_dict=False)
  File "/home/asb/projects/python-digitalocean/digitalocean/Droplet.py", line 274, in take_snapshot
    return_dict
  File "/home/asb/projects/python-digitalocean/digitalocean/Droplet.py", line 159, in _perform_action
    params=params
  File "/home/asb/projects/python-digitalocean/digitalocean/Droplet.py", line 118, in get_data
    data = super(Droplet, self).get_data(*args, **kwargs)
  File "/home/asb/projects/python-digitalocean/digitalocean/baseapi.py", line 95, in get_data
    req = self.__perform_request(url, type, params)
  File "/home/asb/projects/python-digitalocean/digitalocean/baseapi.py", line 80, in __perform_request
    r = self.__perform_post(url, headers=headers, params=params)
  File "/home/asb/projects/python-digitalocean/digitalocean/baseapi.py", line 48, in __perform_post
    return requests.post(url, headers=headers, json=params)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'json'

I'm a bit conflicted on this issue as using json instead of query params is definitely the "right" thing to do, but Ubuntu 14.04 is an important target for me personally (https://github.com/andrewsomething/digitalocean-indicator) A more graceful fall back would be best.

@koalalorenzo
Copy link
Owner

I am thinking about that, because if we have to support older versions, then we need another solution. What about avoid requests and use another library? What if you install the latest version using pip?

@koalalorenzo
Copy link
Owner

@andrewsomething By running the tests with the dockerfile I wrote, it seems working properly on ubuntu 14.04 with both python 2 and python 3... can you check? Probably it is just a question of mocking the requests...

@andrewsomething
Copy link
Contributor Author

Installing requests with pip will get the latest version, and I can confirm that it allows the tests to pass. I can also confirm the Docker image successfully runs the tests (great idea!).

The problem for me is that I distribute digitalocean-indicator as Debian package. As it's a GUI app, asking end users to use pip isn't great. I guess I can backport requests though...

@koalalorenzo
Copy link
Owner

What about a specific environment?

@tomscytale
Copy link
Contributor

requests 2.4.2 was only released on 2014-10-05 so I guess it needs to be supported.

requests.post(url, json=data)

is really just a shortcut for

requests.post(url, data=json.dumps(data), headers={"content-type": "text/javascript"))

or something pretty similar.

So to support older versions of requests we could change to that

Alternatively we could go back to using query parameters but just make sure to translate booleans properly. However I think JSON's better.

@p00j4
Copy link

p00j4 commented Sep 9, 2016

2.7.6 also it doesn't work, but works on 2.7.11

@koalalorenzo
Copy link
Owner

Same problem? Should we update the requirement?

@raghvendra95
Copy link

working fine with 2.7.6,issue with 2.7.9.

@koalalorenzo
Copy link
Owner

Is this a problem related to python-digital ocean dependency? If so, I may need to understand the bug that you are reporting and which version is fixing this... or alternatively, change the code to work properly with the latest version available. Can somebody help me in this process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants