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

Chunked media upload keeps timing out #488

Open
new-yen opened this issue Mar 28, 2018 · 1 comment
Open

Chunked media upload keeps timing out #488

new-yen opened this issue Mar 28, 2018 · 1 comment

Comments

@new-yen
Copy link

new-yen commented Mar 28, 2018

Hello,

I am pretty new to Python or coding in general and I am trying to set up my raspberry Pi zero to tweet Gifs. Unfortunately I had no luck so far, I managed to make a normal tweet but whenever I try it with a JPEG or a GIF the Python script just times out.

This is the code I have been trying:

`
from twython import Twython

APP_KEY = 'my APP_KEY'
APP_SECRET = 'my APP_SECRET'
OAUTH_TOKEN = 'my OAUTH_TOKEN'
OAUTH_TOKEN_SECRET = 'my OAUTH_TOKEN_SECRET'

twitter = Twython(APP_KEY,
APP_SECRET,
OAUTH_TOKEN,
OAUTH_TOKEN_SECRET)

print('Posting to Twitter')
photo = open('/home/pi/gifcam/gifs/test_1.jpg', 'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status='Taken with #PIX-E Gif Camera', media_ids=[response['media_id']])
`

I was looking into the Twython code a bit and found these lines below from endpoints.py for the media upload. I was wondering if the problem result from the the fact that the media.upload doesn't go through the same three stages like the upload.video (INIT, APPEND, FINALIZE) as described in the Twitter API documentation chunked POST media/upload

Every help with this issue is much appreciated.
Thanks and best regards
david

This is the code from "endpoints.py" for the media upload:
def upload_media(self, **params): """Uploads media file to Twitter servers. The file will be available to be attached to a status for 60 minutes. To attach to a update, pass a list of returned media ids to the :meth:update_status` method using the media_ids param.
Docs:
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
"""
# https://developer.twitter.com/en/docs/media/upload-media/api-reference/get-media-upload-status
if params and params.get('command', '') == 'STATUS':
return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params)

    return self.post('https://upload.twitter.com/1.1/media/upload.json', `params=params)`

for the video upload:

def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False):
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached
to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the :meth:update_status method using the media_ids param.
Upload happens in 3 stages:
- INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error.
- APPEND calls each with media chunk. This returns a 204(No Content) if chunk is received.
- FINALIZE call to complete media upload. This returns media_id to be used with status update.
Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each.
Docs:
https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload
`

@new-yen new-yen changed the title Chunked media upload Chunked media upload keeps timing out Mar 29, 2018
@new-yen
Copy link
Author

new-yen commented Apr 1, 2018

The missing chunked upload might still lead to problems with bigger file sizes, which was not an issue in my case, as I only tried to upload small images and GIFs.

But I made the upload work for me. I figured out, that my problem was, that I tried running my script in Python 3 but it only works in Python 2.

I think this is worth mentioning and maybe should go in a pull request or did I just miss this information somehow.

cheers
david

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