如何在python中複製以下curl
請求?
curl https://api.box.com/2.0/files/content
-H "Authorization: Bearer TOKEN" -d '{"name": "Wolves owners.ppt", "parent": {"id": "2841136315"}, "size": 15243}'
-X OPTIONS`
當我介紹json.dumps於所述請求授權失敗
以下請求體格式不正確。它只是一個Python字典,嵌套的屬性沒有通過。
h.kwargs['body'] = {"size": 45810, "parent": {"id": "2841136315"}, "name": "83db7037-2037-4f38-8349-255299343e6d"}
first = requests.options(
h.kwargs['url'], headers=h.headers, data=h.kwargs['body']
)
看體設定爲size=45810&parent=id&name=83db7037-2037-4f38-8349-255299343e6d
報頭中的響應上的授權失敗,一旦401
json.dumps被引入所述第二請求是
`{'Content-Length': '62', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept-Encoding': 'gzip, deflate', 'Authorization': 'Bearer TOKEN', 'Accept': '*/*', 'User-Agent': 'python...'}`
second = requests.options(
h.kwargs['url'], headers=h.headers, data=json.dumps(h.kwargs['body'])
)
標題是
`{'Content-Length': '95', 'Accept': '*/*', 'User-Agent': 'python...', 'Accept-Encoding': 'gzip, deflate', 'Authorization': 'Bearer TOKEN'}`
我該如何格式化身體以獲得呼叫而不會搞亂授權?
我試過設置爲第二個請求json的內容類型,但它沒有工作
你哪HTTP響應對於其中場被送到成'第一個請求x-www-form-urlencoded'? – Anentropic 2014-12-19 04:01:25
@Antropic'無效值\'size = 75&parent = id&name = 6951cd4f-f037-44da-9710-821dd9089486.csv' – user2954587 2014-12-19 04:03:11
什麼http代碼? – Anentropic 2014-12-19 04:04:48