[英]Python request returning a JSON Decoder Error
我正在嘗試從網站中提取數據。 我正在使用 Python 請求:
users = requests.get('website name here', headers=headers).json()
我收到此錯誤:
提高 JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我知道我要提取的數據是 JSON,這是其他人收到此錯誤消息時遇到的問題之一。 我的猜測是,因為訪問該站點需要用戶名和密碼,所以它給了我這個錯誤。 會是這樣嗎? 如果是這樣,我該如何解決? 我不想在我的 Python 程序中包含我的登錄信息。
編輯:我現在知道授權不是問題,因為我創建了一個授權令牌,但我仍然遇到同樣的問題。
request.get()
返回響應( Doc ) object 和response.content
將有實際響應。
我建議嘗試:
import json
import requests
headers = {...}
response = requests.get('website name here', headers=headers)
try:
users = json.loads(response.content)
except Exception as ex:
print("Error getting response")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.