有人可以建議使用python呼叫下面的正確語法嗎?
curl "https://sometest.api.token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}"
我的嘗試:
import requests
import json
credentials='1111'
secret='2222'
url = 'https://sometest.api.token'
body = {'client_credentials':credentials,'client_secret':secret}
headers = {'Content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=json.dumps(body), headers=headers)
uj5u.com熱心網友回復:
由于檔案的原因,如果您想發送一些表單編碼的資料,您只需將字典傳遞給 data 引數。
所以你必須嘗試:
import requests
import json
credentials='1111'
secret='2222'
url = 'https://sometest.api.token'
body = {'client_credentials':credentials, 'client_secret':secret}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=body, headers=headers)
而且您在 python 代碼中的引數與 中的引數不同curl,也許您必須檢查它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/420247.html
標籤:
