Fix issues with update profile images causing 500 error.
authorJosh Roesslein <jroesslein@gmail.com>
Tue, 18 Aug 2009 20:19:44 +0000 (15:19 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Tue, 18 Aug 2009 20:19:44 +0000 (15:19 -0500)
ROADMAP
tweepy/api.py
tweepy/binder.py

diff --git a/ROADMAP b/ROADMAP
index 7f69a9725ba899f56eedea9e4f6aac43fc81a82a..3a30a6ae77b27c715c96f84a9f1334386e7761cd 100644 (file)
--- a/ROADMAP
+++ b/ROADMAP
@@ -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...
 =========
index 1e9a603d3c6a1d2950a840ad2e4e9118329c57ca..03cd2dc3f5c7c8a82538b14ff0c9b978ac9b0017 100644 (file)
@@ -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
 
index 5b3fe62bb7c727e65cc6eb708b6c496dac4b6f8f..9fe2432ee1416b41d134615afca349807065a030 100644 (file)
@@ -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()