如何求解期望值:行1列1(字符0)?

2024-09-23 22:20:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直试图解决这个错误很长时间,并尝试了许多方法来解决它。请帮我做同样的事。代码和错误在屏幕截图中。你知道吗

url = "https://www.moneycontrol.com/financials/adani%20ports/balance-
sheetVI/MPS"
response = requests.get(url, timeout=240)
response.status_code
content = response.json()
content.keys()

回溯:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-90-f7433ffb5f41> in <module>()
      1 url = "https://www.moneycontrol.com/financials/adani%20ports/balance-sheetVI/MPS"
      2 response = requests.get(url, timeout=240)
----> 3 content = response.json()
      4 content

3 frames
/usr/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
    355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
--> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
    358         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Tags: httpscomjsonurlvalueresponsewww错误
1条回答
网友
1楼 · 发布于 2024-09-23 22:20:35

我认为您应该添加一些头并确定您接受json数据。 请尝试以下代码:

url = "https://www.moneycontrol.com/financials/adani%20ports/balance-
sheetVI/MPS"    
headers = {'content-type': 'application/json'}
response = requests.get(url, headers=headers)

相关问题 更多 >