I need to upload file to Facebook via API. To do it i tried to use Curl and everything works great:
curl -F 'source=@/file.mp4' -F 'access_token=secret' https://graph.facebook.com/v4.0/act_000042/advideos
Also i'm trying implement the same in Python using Requests:
import requests # requests==2.19.1
with open('/file.mp4', 'rb') as filecontent:
response = requests.post(
'https://graph.facebook.com/v4.0/act_000042/advideos',
data={
'access_token': 'secret',
},
files={
'source': filecontent,
}
)
And i get the same error: {'error': {'code': 1, 'message': 'An unknown error occurred'}. So there is some difference between how Curl uploads files and how Requests uploads them.
What is the difference and how can i implement the same download via Requests?
data=leads to post form, i assumeaccess_tokenhave to be inheaders=or infiles=. Read post-a-multipart-encoded-filev4.0/act_000042/advideosis valid and accepts.mp4. I'm missing anyContent-Typealso.curl,requests.post,headerandfieldsand found no differences.