From: Katsunori SUZUI Date: Fri, 13 Jun 2014 09:00:02 +0000 (+0900) Subject: Fix tweepy.API.update_with_media X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d7ac5d850dfa093fd3a031b966d9de25731eb3bb;p=tweepy.git Fix tweepy.API.update_with_media If filename is an instance of `unicode', L.76 `` 'Content-Disposition: form-data; name="%s"; filename="%s"' % (form_field, filename) '' must be unicode string. Because of it, L. 803 `` body = '\r\n'.join(body) '' fails. Therefore, I made `filename' designed to be percent-encoded str object before formatting. --- diff --git a/tweepy/api.py b/tweepy/api.py index 9e3d64e..9218208 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -4,6 +4,7 @@ import os import mimetypes +import urllib from tweepy.binder import bind_api from tweepy.error import TweepError @@ -788,6 +789,8 @@ class API(object): if file_type not in ['image/gif', 'image/jpeg', 'image/png']: raise TweepError('Invalid file type for image: %s' % file_type) + if isinstance(filename, unicode): + filename = urllib.quote(filename.encode("utf-8")) BOUNDARY = 'Tw3ePy'