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

FileNotFoundError in api.media_upload using the file argument #1412

Closed
fkropfhamer opened this issue Aug 10, 2020 · 0 comments · Fixed by #1413 or #1475
Closed

FileNotFoundError in api.media_upload using the file argument #1412

fkropfhamer opened this issue Aug 10, 2020 · 0 comments · Fixed by #1413 or #1475
Labels
Bug This is regarding a bug with the library
Milestone

Comments

@fkropfhamer
Copy link
Contributor

I tried to upload an image created in memory by using the file argument of api.media_upload

code:

import tweepy
from PIL import Image
import numpy as np
import io

consumer_key=""
consumer_secret=""

access_token=""
access_token_secret=""

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
    
X = array = np.random.randint(255, size=(900, 1600, 3), dtype=np.uint8)

im = Image.fromarray(array, mode="RGB")
    
b = io.BytesIO()

im.save(b, "PNG")
b.seek(0)
fp = io.BufferedReader(b)
    
media = api.media_upload('test.png', file=fp)

api.update_status("message", media_ids=[media.media_id])

returns Error:

Traceback (most recent call last):
  File "/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/main.py", line 42, in <module>
    main()
  File "/main.py", line 36, in main
    media = api.media_upload('test.png', file=h)
  File "/tweepy/api.py", line 225, in media_upload
    file_type = imghdr.what(filename) or mimetypes.guess_type(filename)[0]
  File "/lib/python3.8/imghdr.py", line 16, in what
    f = open(file, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'test.png'
@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label Dec 22, 2020
@Harmon758 Harmon758 added this to the 3.10 milestone Dec 22, 2020
@Harmon758 Harmon758 linked a pull request Dec 22, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants