解决 Python requests 库中 JSONDecodeError: Expecting value 错误
The error "JSONDecodeError: Expecting value" occurs because the response from the URL you are trying to fetch is not in a valid JSON format. This could be due to various reasons such as:\n\n- The URL is not returning a JSON response.\n- The URL is not accessible or is returning an error.\n- The headers or parameters you are sending with the request are incorrect.\n\nTo troubleshoot the issue, you can try the following steps:\n\n1. Check if the URL is accessible and returns the expected response when accessed directly in a browser or using a tool like cURL.\n2. Verify if the headers you are sending with the request are correct and match the requirements of the server. You can refer to the API documentation or contact the server administrator for more information.\n3. Try changing the encoding of the response using r.encoding to see if it resolves the issue. For example, you can try setting r.encoding = 'utf-8' instead of r.encoding = r.apparent_encoding.\n4. If none of the above steps work, it is possible that the server is not returning a valid JSON response. In this case, you may need to review the API documentation or contact the server administrator for assistance.
原文地址: https://www.cveoy.top/t/topic/pZup 著作权归作者所有。请勿转载和采集!