img_url = 'https://upload.twitter.com/1.1/media/upload.json'
auth = OAuth1('',
'',
'',
'')
file = open('test.png', 'rb')
binary_data = file.read()
file.close()
img_data = requests.post(img_url, auth = auth, params = {'media': binary_data})
print(img_data)
returns
Response [400]
Note that posting a normal text status update via https://api.twitter.com/1.1/statuses/update.json works just fine so I assume the bad request doesn't lie in the authorization. I have also tried encoding the image in base 64 then passing that to the 'media_data' parameter which also returned the same response.
So far I've been following the official api reference on https://dev.twitter.com/rest/reference/post/media/upload