2016-03-03 37 views
1

我試圖上傳本地驅動器,但有些東西它不是通過蟒蛇的視頻上傳到了Facebook從本地驅動器

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) 

輸出返回InsecurePlatformWarning的請求後上傳文件的視頻:一個真正的SSLContext對象不可用。這可以防止urllib3正確配置SSL,並可能導致某些SSL連接失敗。有關更多信息,請參閱https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning。 InsecurePlatformWarning

+0

您是否嘗試了參考文獻中包含的建議? – mhawke

回答

2

InsecurePlatformWarning是一個警告,而不是一個錯誤。您仍然可以成功上傳視頻文件。

事實上,您的代碼將發送一個內容類型爲application/x-www-form-urlencoded的POST HTTP請求,並且它會對錶單數據進行適當編碼。 不是實際上傳文件,它只是在source表單變量中發佈文件的位置。

我認爲你需要上傳的文件使用multipart/form-data的內容類型爲described這裏。指定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)