程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python的requests模塊json報錯

編輯:Python
問題遇到的現象和發生背景 在python中requests使用json時報錯(異常)
問題相關代碼,請勿粘貼截圖

import json

import requests
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33'
}
url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?hKHnQfLv=5'
data = {
'on': 'true',
'page': '1',
'pageSize': '15',
'productName':'',
'conditionType': '1',
'applyname':'',
'applysn':''
}
response = requests.post(url=url,headers=header,data=data).json()

運行結果及報錯內容

D:\anaconda\anconda\python.exe D:/pythonProject1/藥監總局.py
Traceback (most recent call last):
File "D:\anaconda\anconda\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "D:\anaconda\anconda\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "D:\anaconda\anconda\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\anaconda\anconda\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 4 column 1 (char 6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\pythonProject1\藥監總局.py", line 17, in
response = requests.post(url=url,headers=header,data=data).json()
File "D:\anaconda\anconda\lib\site-packages\requests\models.py", line 917, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value]

: 6

進程已結束,退出代碼1

我的解答思路和嘗試過的方法
我想要達到的結果

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved