Commit 4fd1096d authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Fix issues with update profile images causing 500 error.

parent 1e6485cd
......@@ -7,7 +7,6 @@ The plan of attack for the next version of Tweepy.
+ prepare for social graph changes mentioned on mailinglist
+ finish search api
+ autodetect authenticated user's ID [DONE]
+ timeline paging
Future...
=========
......
......@@ -247,22 +247,24 @@ class API(object):
"""Update profile image"""
def update_profile_image(self, filename):
headers, post_data = _pack_image(filename, 700)
bind_api(
path = '/account/update_profile_image.json',
method = 'POST',
parser = parse_none,
require_auth = True
)(self, post_data = _pack_image(filename, 700))
)(self, post_data=post_data, headers=headers)
"""Update profile background image"""
def update_profile_background_image(self, filename, *args, **kargs):
headers, post_data = _pack_image(filename, 800)
bind_api(
path = '/account/update_profile_background_image.json',
method = 'POST',
parser = parse_none,
allowed_param = ['tile'],
require_auth = True
)(self, post_data = _pack_image(filename, 800))
)(self, post_data=post_data, headers=headers)
"""Update profile"""
update_profile = bind_api(
......@@ -438,7 +440,7 @@ def _pack_image(filename, max_size):
# build the mulitpart-formdata body
fp = open(filename, 'rb')
BOUNDARY = '--Tw3ePy'
BOUNDARY = 'Tw3ePy'
body = []
body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="image"; filename="%s"' % filename)
......@@ -448,6 +450,13 @@ def _pack_image(filename, max_size):
body.append('--' + BOUNDARY + '--')
body.append('')
fp.close()
body = '\r\n'.join(body)
return '\r\n'.join(body)
# build headers
headers = {
'Content-Type': 'multipart/form-data; boundary=Tw3ePy',
'Content-Length': len(body)
}
return headers, body
......@@ -23,6 +23,13 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
else:
post_data = None
# check for headers
if 'headers' in kargs:
headers = dict(kargs['headers'])
del kargs['headers']
else:
headers = {}
# build parameter dict
if allowed_param:
parameters = {}
......@@ -42,11 +49,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
raise TweepError('This method takes no parameters!')
parameters = None
# Assemble headers
headers = {
'User-Agent': 'tweepy'
}
# Build url with parameters
if parameters:
url = '%s?%s' % (api.api_root + path, urllib.urlencode(parameters))
......@@ -79,7 +81,7 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
conn = httplib.HTTPConnection(_host, timeout=10.0)
# Build request
conn.request(method, url, headers=headers)
conn.request(method, url, headers=headers, body=post_data)
# Get response
resp = conn.getresponse()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment