Python 从本地驱动器向Facebook上传视频

Python 从本地驱动器向Facebook上传视频,python,facebook-graph-api,python-requests,Python,Facebook Graph Api,Python Requests,我正在尝试从本地驱动器上传视频,但有些人认为它没有通过python的请求帖子上传文件 import requests import json accesstoken = '-----------------' desc = 'This is test' titl = 'Testing Video' vidfbpath = '/tempvideos/0xjwseCVUlU.mp4' source = open(vidfbpath, 'rb') # need binary rep of thi

我正在尝试从本地驱动器上传视频,但有些人认为它没有通过python的请求帖子上传文件

import requests
import json

accesstoken = '-----------------'
desc = 'This is test'
titl = 'Testing Video'
vidfbpath = '/tempvideos/0xjwseCVUlU.mp4'
source = open(vidfbpath, 'rb')

 # need binary rep of this, not sure if this would do it
 fburl = 'https://graph-video.facebook.com/v2.0/1098719680172720/videos?access_token='+str(accesstoken) 
 # put it all together to post to facebook
 m = {'description': desc,
        'title': titl,
        'source': vidfbpath,}

 r = requests.post(fburl, data=m).text
 fb_res = json.loads(r)
输出返回UnsecurePlatformWarning:真正的SSLContext对象不可用。这会阻止urllib3正确配置SSL,并可能导致某些SSL连接失败。有关详细信息,请参阅。
不安全平台警告是一个警告,而不是错误。你仍然有很好的机会成功上传你的视频文件

实际上,您的代码将发送内容类型为
application/x-www-form-urlencoded
的POST HTTP请求,并对表单数据进行适当编码。这实际上并没有上载文件,它只是将文件的位置发布在
source
表单变量中

我认为您需要使用
multipart/formdata
的内容类型上传文件,如下所示。指定mp4文件的内容类型也是一个好主意。大概是这样的:

m = {'description': desc,
      'title': titl,}

files = {'source': ('0xjwseCVUlU.mp4', open('/tempvideos/0xjwseCVUlU.mp4', 'rb'), 'video/mp4')}

r = requests.post(fburl, data=m, files=files)

你试过参考资料中的建议了吗?