You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The JPEG file /tmp/tmp.29bSaJRIFj is tweeted along with the text "foo".
Actual results:
Traceback (most recent call last):
File "./tweetIt.py", line 18, in <module>
media_ids=[api.media_upload(sys.argv[2]).media_id_string]
File "/usr/lib/python2.7/site-packages/tweepy/api.py", line 201, in media_upload
headers, post_data = API._pack_image(filename, 3072, form_field='media', f=f)
File "/usr/lib/python2.7/site-packages/tweepy/api.py", line 1323, in _pack_image
raise TweepError('Invalid file type for image: %s' % file_type)
tweepy.error.TweepError: Invalid file type for image: None
Additional information:
The version of Tweepy I'm using is a bit out of date
which guesses the file type based on the file name.
It's very common on Unix-like operating systems for shell scripts to use files the name of which is generated by mktemp. That's how I encountered this issue. Some versions of mktemp support providing a suffix, e.g. $ imgFile=$(mktemp --suffix=.jpg) but some versions of mktemp do not support providing a suffix.
Python 2.7.15 (default, May 16 2018, 17:50:09)
[GCC 8.1.1 20180502 (Red Hat 8.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imghdr
>>> imghdr.what('tmp.29bSaJRIFj')
'jpeg'
The text was updated successfully, but these errors were encountered:
A valid JPEG file is rejected due to it's file name.
Steps to recreate:
Expected results:
The JPEG file /tmp/tmp.29bSaJRIFj is tweeted along with the text "foo".
Actual results:
Additional information:
The version of Tweepy I'm using is a bit out of date
but I can see the issue will occur with the current version too because the behaviour results from using mimetypes.guess_type()
tweepy/tweepy/api.py
Line 1316 in 8ad187e
which guesses the file type based on the file name.
It's very common on Unix-like operating systems for shell scripts to use files the name of which is generated by mktemp. That's how I encountered this issue. Some versions of mktemp support providing a suffix, e.g.
$ imgFile=$(mktemp --suffix=.jpg)
but some versions of mktemp do not support providing a suffix.imghdr https://docs.python.org/2/library/imghdr.html determines the type of image contained in a file by looking at the file's contents.
The text was updated successfully, but these errors were encountered: