【问题标题】:how to get response data from a python post request [duplicate]如何从python发布请求中获取响应数据[重复]
【发布时间】:2021-05-12 23:53:17
【问题描述】:

我正在运行一个 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脚本

import requests
import os

url = str(os.environ.get('API_SERVER_URL'))+'login/user'
head = {'accept': 'application/json', 'Content-Type': 'application/json'}
data = {"username": "admin", "password": "admin"}             }
response = requests.post(url, json=data, headers=head, verify=False)

print(response)

我得到的只是 200 响应

<Response [200]>

【问题讨论】:

标签: python-3.x http python-requests httpresponse


【解决方案1】:

获取响应的内容怎么样?

例如:

print(response.text)

或者,如果您期望JSON

print(response.json())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2022-01-25
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多