簡體   English   中英

Python請求:requests.get(url).json()錯誤

[英]Python Requests: requests.get(url).json() Error

當嘗試使用python請求時,我獲得以下內容:當我嘗試確保請求是json格式時。 使用requests.get(url)時的requests.get(url)<Response [200]>

但是,當使用request.get(url).json()我獲得以下內容:

  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

打印requests.get(url) .headers給出以下內容:

{'Server': 'nginx/1.10.3 (Ubuntu)', 'Date': 'Mon, 01 Apr 2019 21:03:28 GMT', 'Content-Type': 'text/html', 'Last-Modified': 'Mon, 25 Mar 2019 21:25:01 GMT', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'ETag': 'W/"5c99472d-806"', 'Strict-Transport-Security': 'max-age=63072000; includeSubdomains', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip'}

我已經嘗試剪掉某些字符,如<,>,\\,\\ 0但這並沒有影響結果。

以下請求應該有效。

import requests requests.get(URL, headers={'content-type':'application/json'}).json()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM