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

Fix for broken PUT methods #414 #415

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion twitter/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,12 @@ def __call__(self, **kwargs):
headers.update(self.auth.generate_headers())
# Use urlencoded oauth args with no params when sending media
# via multipart and send it directly via uri even for post
url_args = {} if media or jsondata else kwargs
if method == "PUT" and _id:
# the two PUT method APIs both require uri id parameter
url_args['id'] = _id
arg_data = self.auth.encode_params(
url_base, method, {} if media or jsondata else kwargs)
url_base, method, url_args)
if method == 'GET' or media or jsondata:
url_base += '?' + arg_data
else:
Expand Down Expand Up @@ -328,6 +332,13 @@ def __call__(self, **kwargs):
headers[actually_bytes(k)] = actually_bytes(headers.pop(k))

req = urllib_request.Request(url_base, data=body, headers=headers)
# Horrible hack, the python2/urllib2 version of request doesn't
# take a method parameter, but we can overwrite the class
# get_method() function to a lambda function that always returns
# the method we want...
# https://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python/111988#111988
req.get_method = lambda: method

if self.retry:
return self._handle_response_with_retry(req, uri, arg_data, _timeout)
else:
Expand Down