2017-05-31 242 views
0

我與Dropbox的的Python API中的工作,試圖以下curl命令轉換爲Python的要求:捲曲蟒蛇請求轉換

curl -X POST https://content.dropboxapi.com/2/files/download \ 
     --header "Authorization: Bearer <ACCESS_TOKEN>" \ 
     --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Prime_Numbers.txt\"}" 

我至今翻譯:

downloadHeader={"Authorization: " + authorization} 

downloadURL = "https://content.dropboxapi.com/2/files/download" 

downloadPayload = {"Dropbox-API-Arg": {"path": "/" + dbPATH}} 

downloadResponse = requests.post(downloadURL, data=json.dumps(downloadPayload), headers=downloadHeader) 

然而,當我運行這個我得到以下錯誤:

for header in headers.items(): AttributeError: 'set' object has no attribute 'items'

任何人都可以給我一些反饋?我相信我的授權值,因爲它的工作中,我複製一個單獨的請求,並粘貼如下:

MDlink = "https://api.dropboxapi.com/2/sharing/get_shared_link_metadata" 
authorization = "Bearer " + ACCESS_TOKEN 
headers={"Content-Type":"application/json", "Authorization": authorization} 
payload = {"url": imageLink} 
response = requests.request("POST", MDlink, data=json.dumps(payload), headers=headers) 

非常感謝您!

+0

我建議您應該使用任何調試Web代理,如: [mitmproxy,(pythonic),控制檯/基於Web,免費](http://mitmproxy.org) [提琴手,(贏),GUI,免費]( (www.telerik.com/fiddler) [charles調試代理,(win/java),GUI,商業](https://www.charlesproxy.com) 所有這些都支持二進制串行化流量即AMF), 他們只是把你的http(s)反轉任務變成快樂:) – internety

+0

我從問題和答案中編輯它,但爲了安全起見,你應該禁用該訪問令牌,因爲它是公開發布的。您可以完全撤銷對應用程序的訪問,如果訪問令牌用於您的帳戶,則可以這樣做: https://www.dropbox.com/account/security 或者,您可以僅使用此訪問令牌API: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke – Greg

回答

1

你要這個

downloadHeader={"Authorization: " + authorization} 

downloadHeader={"Authorization": authorization} 

或者更確切地說

downloadHeader={"Authorization": "Bearer <ACCESS_TOKEN>"} 

說明:

{1} # this is a set. It has no .items() 
{1: 1} # this is a dict. You can call .items()