Answers for "user-agent header in request python"

1

python requests set user agent

import requests

url = 'SOME URL'

headers = {
    'User-Agent': 'My User Agent 1.0',
    'From': '[email protected]'  # This is another valid field
}

response = requests.get(url, headers=headers)
Posted by: Guest on September-09-2020
0

why mentioning user agent in request library

#If you are using python requests old version 

import requests

url = 'SOME URL'

# Get a copy of the default headers that requests would use
headers = requests.utils.default_headers()

# Update the headers with your custom ones
# You don't have to worry about case-sensitivity with
# the dictionary keys, because default_headers uses a custom
# CaseInsensitiveDict implementation within requests' source code.
headers.update(
    {
        'User-Agent': 'My User Agent 1.0',
    }
)

response = requests.get(url, headers=headers)
Posted by: Guest on November-09-2020

Code answers related to "user-agent header in request python"

Python Answers by Framework

Browse Popular Code Answers by Language