raise InvalidHeader( requests.exceptions.InvalidHeader: Invalid leading whitespace, reserved character(s), or returncharacter(s) in header value: ' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50'
时间: 2023-12-03 09:45:25 浏览: 248
python中报错"json.decoder.JSONDecodeError: Expecting value:"的解决
5星 · 资源好评率100%
这个错误通常是由于请求头中存在非法字符或格式错误导致的。你需要检查一下请求头中的内容,确保没有多余空格或者非法字符,并且符合标准的格式要求。你可以参考下面的示例格式:
```
{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/json"
}
```
如果还有问题,你可以尝试使用 Python 的 requests 模块来发送请求,并且在发送请求时指定正确的请求头。例如:
```python
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
```
阅读全文