Python 3.x 如何从python post请求中获取响应数据
我有一个Python 3.x 如何从python post请求中获取响应数据,python-3.x,http,python-requests,httpresponse,Python 3.x,Http,Python Requests,Httpresponse,我有一个openapi3服务器正在运行,我正试图用它进行身份验证 我可以用curl毫无问题地完成它 curl -k -X POST "https://localhost:8787/api/login/user" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"username\":\"admin\
openapi3
服务器正在运行,我正试图用它进行身份验证
我可以用curl
毫无问题地完成它
curl -k -X POST "https://localhost:8787/api/login/user" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"username\":\"admin\",\"password\":\"admin\"}"
#and i get the token back
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNjEyODY3NDU3LCJleHAiOjE2MTI4NzEwNTd9.9eFgomcpJbinN7L4X1VOHfZGvJeUvHiv6WPjslba1To
但是当使用python
时,我只得到响应代码(200
),没有包含令牌的数据
这是我的python脚本
导入请求
导入操作系统
url=str(os.environ.get('API\u SERVER\u url'))+'login/user'
head={'accept':'application/json','Content Type':'application/json'}
数据={“用户名”:“管理员”,“密码”:“管理员”}
response=requests.post(url,json=data,headers=head,verify=False)
打印(答复)
我得到的答复是200
<Response [200]>
获取响应的内容如何 例如:
print(response.text)
或者,如果您希望使用JSON
:
print(response.json())
这能回答你的问题吗,