求助:找不到错误点了。 跑不起来
import requestsurl = "https://movie.douban.com/j/chart/top_list"
# 重新封装参数
param = {
"type": "24",
"interval_id": "100:90",
"action": " ",
"start": 0,
"limit": 20,
}
header = {
"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.62 Safari/537.36"
}
resp = requests.get(url=url, params=param, headers=header)
print(resp.text) 错误信息
Python 3.11.0a7 (main, Apr5 2022, 21:27:39) on win32
Type "help", "copyright", "credits" or "license()" for more information.
==================== RESTART: C:/Users/zqlcpu/Desktop/3.0.py ===================
Traceback (most recent call last):
File "C:/Users/zqlcpu/Desktop/3.0.py", line 21, in <module>
resp = requests.get(url=url, params=param, headers=header)
File "E:\python3.10.4\Lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "E:\python3.10.4\Lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "E:\python3.10.4\Lib\site-packages\requests\sessions.py", line 515, in request
prep = self.prepare_request(req)
File "E:\python3.10.4\Lib\site-packages\requests\sessions.py", line 443, in prepare_request
p.prepare(
File "E:\python3.10.4\Lib\site-packages\requests\models.py", line 319, in prepare
self.prepare_headers(headers)
File "E:\python3.10.4\Lib\site-packages\requests\models.py", line 453, in prepare_headers
check_header_validity(header)
File "E:\python3.10.4\Lib\site-packages\requests\utils.py", line 1025, in check_header_validity
raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
requests.exceptions.InvalidHeader: Invalid return character or leading space in header: User-Agent 你的UA里有个空格,去掉就好了。 非常感谢。 zqlcpu 发表于 2022-5-29 10:39
非常感谢。
Invalid return character or leading space in header: User-Agent
标头中的返回字符或前导空格无效:User Agent
百度翻译的结果 https://curlconverter.com/
你值得拥有 也在刚开始学习
页:
[1]