【发布时间】:2019-08-17 10:09:32
【问题描述】:
我在 Python 中有以下代码,它正在对 OAuth2 令牌发出 POST 请求。它使用基本身份验证。 代码运行良好,但我想将其“翻译”为 curl。
代码:
#Authorization: Basic c29tZV91c2VyOnBhc3M=
#some_user:pass = base64decode('c29tZV91c2VyOnBhc3M=')
def get_access_token():
burp0_url = "https://myurl:443/api/oauth/token"
burp0_headers = {"Accept": "application/json", "Authorization": "Basic c29tZV91c2VyOnBhc3M=", "Content-Type": "application/x-www-form-urlencoded", "Connection": "close", "Accept-Encoding": "gzip, deflate", "User-Agent": "okhttp/3.0.1"}
burp0_data={"grant_type": "client_credentials"}
return json.loads(requests.post(burp0_url, headers=burp0_headers,
data=burp0_data).text)['access_token']
我的猜测是它看起来像这样:
curl -v -XPOST -H 'Authorization: Basic c29tZV91c2VyOnBhc3M=' --header 'Accept: application/json' --header 'Connection: close' --header 'Accept-Encoding: gzip, deflate' --header 'User-Agent: okhttp/3.0.1' --data '{"grant_type": "client_credentials"}' https://myurl:443/api/oauth/token
但是我不断收到 HTTP/1.1 400 及以下
* 书写体失败 (0 != 10)
* 写入数据失败
* 停止暂停流!
* 关闭连接 0
你能帮帮我吗?
【问题讨论】:
标签: python json http curl request