我連接到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 –