facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.29k stars 635 forks source link

ad video failed to upload with windows path provided or utf-8 chars in path #483

Closed cszichao closed 6 years ago

cszichao commented 6 years ago

code

video = AdVideo(parent_id='act_xxxxxxxxx')
video[AdVideo.Field.filepath] = r'C:\some\path\to\video.mp4'
video.remote_create()

execute failed with error Video Upload Time Out:

{"error":{"message":"Service temporarily unavailable","type":"OAuthException","is_transient":true,"code":2,"error_subcode":1363030,"error_user_title":"Video Upload Time Out","error_user_msg":"Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again.","fbtrace_id":"Fbxxxxxx"}}

but

video[AdVideo.Field.filepath] = 'video.mp4' # in relative path
video[AdVideo.Field.filepath] = '/some/path/to/video.mp4' # on linux or macOS

works fine.

This is caused by the requests lib that change the filename header in Content-Disposition into filename*=utf-8 header when the \ path provided. While the facebook graph-video server seems do not recognize the filename*=utf-8 header

Problem of windows path without utf-8 char in filename can be solved by change https://github.com/facebook/facebook-python-business-sdk/blob/e2f279a62b7e6c7fd30a080b4be8103c7303a715/facebook_business/video_uploader.py#L216 into

os.path.basename(context.file_path)
jingping2015 commented 6 years ago

Thanks for reporting this, this will fix in our next release.