[英]How to Convert this Curl to Python requests
卷曲命令
curl --user "github" --request POST --data '{"description":"Created via API","public":"true","files":{"587":{"content":"adasdaskdasjsadsasdjfcsdjsdjcsdjcsdjcsdjcfsdjsdjfjsdfjsdfsdfsjdfmdsfdsf"}}' https://api.github.com/gists
然后要求輸入密碼並創建要點。
這給出了JSON錯誤:
url = 'https://api.github.com/gists'
auth = ('github','password')
requests.post(url,auth=auth,data={
"description": "the description for this gist",
"public": False,
"files": {
"file1.txt": {
"content": "String file contents"
}
}
})
錯誤: {"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/v3"}
有什么想法我的請求錯了嗎?
我知道這是一個古老的問題,但是如果有人像我一樣在這里偶然發現:
如果您使用的是2.4.2版或更高版本的請求,則應該可以使用requests.post(url, json=<your dictionary>)
。
有關更多詳細信息,請參見此答案: Python請求帶參數數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.