TypeError:request()得到了意外的关键字参数'header'-当我使用header,403错误-没有header

问题描述 投票:-1回答:2

我正在尝试从this网站获取简报信息,但始终获得状态码:403,因此尝试使用标头,但得到了[[TypeError:request()得到了意外的关键字参数'header'

代码:] >>import requests head = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0'} url = "https://www.accuweather.com/en/bd/dhaka/28143/current-weather/28143" pageObj = requests.get(url, header = head) print("Status code: " + str(pageObj.status_code)) # *for testing purpose*

错误:

] >>Traceback (most recent call last): File "F:/Python/PyCharm Community Edition 2019.2.3/Workshop/WEB_SCRAPING/test2.py", line 6, in <module> pageObj = requests.get(url, header = head) File "F:\Python\PyCharm Community Edition 2019.2.3\Workshop\WEB_SCRAPING\venv\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "F:\Python\PyCharm Community Edition 2019.2.3\Workshop\WEB_SCRAPING\venv\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs) TypeError: request() got an unexpected keyword argument 'header'
header from firefox dev tool

我在做什么错?

我正在尝试从该网站获取简报信息,但始终获取状态代码:403,因此尝试使用标头但得到TypeError:request()得到了意外的关键字参数'header'代码:import ...

python html python-requests http-status-code-403
2个回答
0
投票
使用pageObj = requests.get(url, headers=head)

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.