]> jfr.im git - z_archive/twitter.git/commitdiff
Merge branch 'master' of github.com:sixohsix/twitter
authorRouxRC <redacted>
Mon, 22 Sep 2014 18:06:34 +0000 (20:06 +0200)
committerRouxRC <redacted>
Mon, 22 Sep 2014 18:06:34 +0000 (20:06 +0200)
README
twitter/api.py

diff --git a/README b/README
index bc2eec0a3225db05d3142369368fb1875986d06c..1a1bc782c4f6e0d6307b9ad461c1f7f089efa416 100644 (file)
--- a/README
+++ b/README
@@ -125,12 +125,14 @@ 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 ★"
 with open("example.png", "rb") as imagefile:
-    params = {"media[]": imagefile.read(), "status": "PTT"}
+    params = {"media[]": imagefile.read(), "status": status}
 t.statuses.update_with_media(**params)
 
 # Or by sending a base64 encoded image:
-params = {"media[]": base64_image, "status": "PTT", "_base64": True}
+params = {"media[]": base64_image, "status": status, "_base64": True}
 t.statuses.update_with_media(**params)
 ```
 
index 5e6d20af50bb92a5f62e2cd86f8d4ed628350239..14fe20e183dd64eed4a21c2d60b12aa5082ddf41 100644 (file)
@@ -262,6 +262,11 @@ class TwitterCall(object):
             headers['Content-Type'] = \
                 'multipart/form-data; boundary=%s' % BOUNDARY
 
+        if sys.version_info[:2] == (2, 7):
+            uriBase = uriBase.encode("utf-8")
+            for k in headers:
+                headers[k.encode('utf-8')] = headers.pop(k)
+
         req = urllib_request.Request(uriBase, body, headers)
         return self._handle_response(req, uri, arg_data, _timeout)
 
@@ -361,12 +366,14 @@ 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 ★"
         with open("example.png", "rb") as imagefile:
-            params = {"media[]": imagefile.read(), "status": "PTT"}
+            params = {"media[]": imagefile.read(), "status": status}
         t.statuses.update_with_media(**params)
 
         # Or by sending a base64 encoded image:
-        params = {"media[]": base64_image, "status": "PTT", "_base64": True}
+        params = {"media[]": base64_image, "status": status, "_base64": True}
         t.statuses.update_with_media(**params)