Tag Archives: Python Requests Error

[Solved] Python Requests Error: simplejson.errors.JSONDecodeError: Expecting value

Problem: when running the interface automation script, the requested data is correct, but it keeps reporting error: simplejson.errors Jsondecodeerror: expecting value


reason:
the reason for the error reported by the author here is that this interface returns: response in the non-JSON format
while in the basic interface code, the return is res.json()

Solution:
Modify to return text, or add an exception capture

exception capture

Python Requests Error: Max retries exceeded with url

Use the requests library to request url, this error will occur, the reason is:

The server is overloaded, and no more links can be established. There are 4 possibilities:

  1. Too many http connections are not closed.
  2. The machine’s memory is insufficient.
  3. Another possibility is that the IP is blocked by the target website due to the high request frequency
  4. The requested URL address is wrong

Solution:

1. increase the number of retry connections
requests.adapters.DEFAULT_RETRIES = 5

2. close redundant connections
requests uses the urllib3 library, the default http connection is keep-alive, requests set False to close.
Operation method:
s = requests.session()
s.keep_alive = False