]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
Merge pull request #255 from bbolli/speedup-method-for-uri
[z_archive/twitter.git] / twitter / api.py
index 51024ccede2d87b4556919d22b750c37bd47564e..fd33edd343e3ec6dc84ce17d45b7bacfff97f14c 100644 (file)
@@ -256,13 +256,18 @@ class TwitterCall(object):
                 bod.append('--' + BOUNDARY)
                 bod.append('Content-Disposition: form-data; name="%s"' % k)
                 bod.append('')
+                if sys.version_info[:2] <= (2, 7):
+                    try:
+                        v = v.decode("utf-8")
+                    except:
+                        pass
                 bod.append(v)
             bod.append('--' + BOUNDARY + '--')
             body = '\r\n'.join(bod).encode('utf8')
             headers['Content-Type'] = \
                 'multipart/form-data; boundary=%s' % BOUNDARY
 
-            if sys.version_info[:2] == (2, 7):
+            if sys.version_info[:2] <= (2, 7):
                 uriBase = uriBase.encode("utf-8")
                 for k in headers:
                     headers[k.encode('utf-8')] = headers.pop(k)
@@ -366,8 +371,7 @@ class Twitter(TwitterCall):
 
         # Send a tweet with an image included (or set your banner or logo similarily)
         # by just reading your image from the web or a file in a string:
-        # Note that the text sent as status along with the picture must be unicode.
-        status = u"PTT ★"       # or with python 3: status = "PTT ★"
+        status = "PTT ★"
         with open("example.png", "rb") as imagefile:
             params = {"media[]": imagefile.read(), "status": status}
         t.statuses.update_with_media(**params)