twitter-api-client icon indicating copy to clipboard operation
twitter-api-client copied to clipboard

Cannot upload .webp media

Open code-switched opened this issue 11 months ago • 0 comments

.webp is supported by the API via Twitter Media Best Practices

supported-media-types

If you try to upload a .webp image the library throws an error, for example...

Code: account.tweet(text, media=[{"media": "image.webp", "alt": "some nice words about img"}])

Will produce this error:

Traceback (most recent call last):
  File "main.py", line 150, in <module>
    send_tweet = alerts.twt(tweet["text"], tweet["media"])
  File "alerts.py", line 48, in twt
    tweet_sent = account.tweet(alert, media=media)
  File "venv\lib\site-packages\twitter\account.py", line 160, in tweet
    media_id = self._upload_media(m['media'])
  File "venv\lib\site-packages\twitter\account.py", line 512, in _upload_media
    media_category = f'{upload_type}_gif' if 'gif' in media_type else f'{upload_type}_{media_type.split("/")[0]}'
TypeError: argument of type 'NoneType' is not iterable

But if you go to venv\lib\site-packages\twitter\account.py Line 510 and add:

# Add .webp MIME type
mimetypes.add_type('image/webp', '.webp')

Now you can upload .webp media

Issues aside, thank you for maintaining this Trevor <3

code-switched avatar Feb 29 '24 05:02 code-switched