Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"tweepy.error.TweepError: Could not determine file type" error when trying to upload jpg image. #1411

Closed
AlbertCoolGuy opened this issue Aug 2, 2020 · 3 comments
Labels
Bug This is regarding a bug with the library
Milestone

Comments

@AlbertCoolGuy
Copy link

AlbertCoolGuy commented Aug 2, 2020

I'm trying to upload a image using this code:

media = api.media_upload('quote.jpg', f)
api.update_status(status="foo", media_ids=[media.media_id_string])

Expected Results

Tweepy uploads the image with the message "foo".

Actual Results

Tweepy fails to upload the image because it can't guess the filetype using imghdr.what().

Possible Solution

Use mimetypes and/or magic as a fallback if imghdr fails.

Traceback

Traceback (most recent call last):
  File "planetexpressbot.py", line 30, in <module>
    media = api.media_upload('quote.jpg', f)
  File "/usr/local/lib/python3.8/site-packages/tweepy/api.py", line 229, in media_upload
    headers, post_data = API._pack_image(filename, max_size,
  File "/usr/local/lib/python3.8/site-packages/tweepy/api.py", line 1392, in _pack_image
    raise TweepError('Could not determine file type')
tweepy.error.TweepError: Could not determine file type
@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label Aug 2, 2020
@Harmon758
Copy link
Member

Would you be able to provide the image in question?

@AlbertCoolGuy
Copy link
Author

AlbertCoolGuy commented Aug 2, 2020

Here it is.
https://anonfiles.com/73c2O0J0oc/quote_jpg

@Harmon758
Copy link
Member

Harmon758 commented Aug 2, 2020

@Harmon758 Harmon758 added this to the 3.10 milestone Aug 2, 2020
This was referenced Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library
Projects
None yet
Development

No branches or pull requests

2 participants