Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7955145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:38:45+00:00 2026-06-04T03:38:45+00:00

I want to send a value for User-agent while requesting a webpage using Python

  • 0

I want to send a value for "User-agent" while requesting a webpage using Python Requests. I am not sure is if it is okay to send this as a part of the header, as in the code below:

debug = {'verbose': sys.stderr}
user_agent = {'User-agent': 'Mozilla/5.0'}
response  = requests.get(url, headers = user_agent, config=debug)

The debug information isn’t showing the headers being sent during the request.

Is it acceptable to send this information in the header? If not, how can I send it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:38:46+00:00Added an answer on June 4, 2026 at 3:38 am

    The user-agent should be specified as a field in the header.

    Here is a list of HTTP header fields, and you’d probably be interested in request-specific fields, which includes User-Agent.

    If you’re using requests v2.13 and newer

    The simplest way to do what you want is to create a dictionary and specify your headers directly, like so:

    import requests
    
    url = 'SOME URL'
    
    headers = {
        'User-Agent': 'My User Agent 1.0',
        'From': 'youremail@domain.example'  # This is another valid field
    }
    
    response = requests.get(url, headers=headers)
    

    If you’re using requests v2.12.x and older

    Older versions of requests clobbered default headers, so you’d want to do the following to preserve default headers and then add your own to them.

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set headers like post variable name and the value and send
I want to send ViewData.model to Special action with the last user data entry.
Say I want to send email to my server, but I want the user
I want to send the value of property_name to headline and property_name_thumb when a
I want to send json service when the user search text on searchbar. Here
I am new to spring. I want send username of logged in user to
I want to send a pfd in bytestream to the user in an updatepanel,
I've installed this django-contact-form app. When I want to send an email to my
I want to be able to change my sendmail boolean value for a user
I have a wix property <Property Id=VAR1 Value=aValue /> And i want to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.