-
I'll see if I can add a pause... assuming the code is relatively straightforward?
verify that the upload_video step is always successful
I'm not sure how I'd do this? The fact it tweets is usually the verification all went ok. Does twitter return "answers" to each step i could somehow ask the code to delve into?
E.g. if video upload = success, go tweet, else stop, hammer time?
-
For a pause, put
import time
near the top, then insert
time.sleep(5.5) # Pause 5.5 seconds
between the upload_video and update_status lines. It'll probably achieve nothing, but it's something I'd try out of curiosity.
For verifying that the upload_video step is successful:
response = api.upload_video(media=video, media_type='video/mp4') api.update_status(status=tweetStr, media_ids=[response['media_id']])
On line one, you're uploading your file to Twitter, and the response (including a unique identifier for the media file you just uploaded) is stashed in the response variable. You need that ID because when you then send your tweet with update_status, you need to attach the file to your tweet, and you do that by passing the ID of the media file along with your tweet: media_ids=[response['media_id']]
To verify the media upload worked, I'd probably start by just printing out response['media_id'] and seeing if it looks sane. E.g.
video = open('5into15.mp4', 'rb') response = api.upload_video(media=video, media_type='video/mp4') print('media_id', response['media_id']) api.update_status(status=tweetStr, media_ids=[response['media_id']])
Out of curiosity does inserting a pause between uploading the video and updating the status make the problem go away. Maybe 5 seconds?
Also, can you verify that the upload_video step is always successful? It could be failing silently and causing the following step to throw the "Bad Request" error.