1import requests
2
3url = 'SOME URL'
4
5headers = {
6 'User-Agent': 'My User Agent 1.0',
7 'From': 'youremail@domain.com' # This is another valid field
8}
9
10response = requests.get(url, headers=headers)
1#If you are using python requests old version
2
3import requests
4
5url = 'SOME URL'
6
7# Get a copy of the default headers that requests would use
8headers = requests.utils.default_headers()
9
10# Update the headers with your custom ones
11# You don't have to worry about case-sensitivity with
12# the dictionary keys, because default_headers uses a custom
13# CaseInsensitiveDict implementation within requests' source code.
14headers.update(
15 {
16 'User-Agent': 'My User Agent 1.0',
17 }
18)
19
20response = requests.get(url, headers=headers)
21