]> jfr.im git - z_archive/twitter.git/commitdiff
handle non unicode text status for twitpic with py2.x for coherence means
authorRouxRC <redacted>
Sun, 28 Sep 2014 22:56:05 +0000 (00:56 +0200)
committerRouxRC <redacted>
Sun, 28 Sep 2014 22:56:05 +0000 (00:56 +0200)
README
twitter/api.py

diff --git a/README b/README
index 1a1bc782c4f6e0d6307b9ad461c1f7f089efa416..56f7d070a5c7efb4354e92d25abd6a47bedd1d71 100644 (file)
--- a/README
+++ b/README
@@ -125,8 +125,7 @@ t.statuses.oembed(_id=1234567890, _method='GET')
 
 # 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)
index 9c065540e4d5c9f2a21be1c7b31a2ab5978d0881..861d4dfde7a5b25ed7c506632dd2ec94cd44d735 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)