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

Cannot upload .webp media #184

Open
code-switched opened this issue Feb 29, 2024 · 0 comments
Open

Cannot upload .webp media #184

code-switched opened this issue Feb 29, 2024 · 0 comments

Comments

@code-switched
Copy link

code-switched commented Feb 29, 2024

.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant