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

Python requests module JSON reports an error

編輯:Python
The phenomenon and background of the problem stay python in requests Use json Times wrong ( abnormal )

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()

Operation results and error reporting contents

D:\anaconda\anconda\python.exe D:/pythonProject1/ General Administration of Drug Administration .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\ General Administration of Drug Administration .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

Process ended , Exit code 1

My solution ideas and tried methods
What I want to achieve

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