我连接到Web API时出现问题,因为我无法获取结果的正文。无法从python中的JSON WEB API请求获取正文
这是我的代码:
import json,requests
url =('URL')
data={"Content-Type":"application/x-wwwform-urlencoded", "Authorization":"Valid JWT Token"}
myResponse1 = requests.get(url,data=data)
print ("status_code:"+ str(myResponse1.status_code))
print ("******************")
print ("text:"+ str(myResponse1.text))
print ("******************")
print ("encoding:"+ str(myResponse1.encoding))
print ("******************")
print ("json:"+ str(myResponse1.json))
print ("******************")
print ("content:"+ str(myResponse1.content))
print ("******************")
print ("body:"+ str(myResponse1.body))
白衣这样的输出:
status_code:401
******************
text:
******************
encoding:None
******************
json:<bound method Response.json of <Response [401]>>
******************
content:b''
******************
Traceback (most recent call last):
File "C:\Users\Carlo\Desktop\Web API\Log-In_API.py", line 28, in <module>
print ("body:"+ str(myResponse1.body))
AttributeError: 'Response' object has no attribute 'body'
现在我不明白为什么,因为当我尝试用邮差的API是给我回体结果:
如果您在我的结果和图片中看到状态,我们有不同的状态,但我不太明白为什么看到我是通行证唱相同的参数
答案所述的问题实际上是在截屏你提供。邮差显示标题部分,但代码不使用任何自定义标题,并将相关的字典输入数据参数。我猜,对于GET请求,它会进入url。 – hamilyon
嘿家伙,我可以问你为什么我对这个问题有负面评分吗?我试图改善我所有的问题,但我不明白为什么我对该问题有负面评分:S –