Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: request() got an unexpected keyword argument 'header' - when i use header,403 error - without header

i am trying scrape information from this website but keep getting status code: 403, So tried using header but got TypeError: request() got an unexpected keyword argument 'header'

Code:

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*

Error:

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

what am i doing wrong?

like image 597
Redwan Hossain Arnob Avatar asked Oct 28 '25 05:10

Redwan Hossain Arnob


1 Answers

The name of the argument is headers, not header. See the docs.

Use pageObj = requests.get(url, headers=head)

like image 119
DeepSpace Avatar answered Oct 29 '25 18:10

DeepSpace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!