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

  • SEARCH
  • Home
  • 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 8174973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:36:04+00:00 2026-06-06T22:36:04+00:00

In python, I want to send a request to a url which will return

  • 0

In python, I want to send a request to a url which will return some information to me. The problem is if I try to access the url from the browser, a popup box appears and asks for a username and password. I have a username and password for this url however, I don’t know how to make python automatically complete these fields to access the URL.

This is my code that returns a 401 error:

bing = "https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%
(term)s&$top=50&$format=json" %__function()
results = urllib2.urlopen(bing).read()

EDIT: Just for clarification, the function function returns a variable called term which is the term being queried in the URL

  • 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-06T22:36:05+00:00Added an answer on June 6, 2026 at 10:36 pm

    You’re most likely facing HTTP basic authentication. This can be done in urllib2 but it’s a bit tiresome. The instructions on how to do this are here:

    http://www.voidspace.org.uk/python/articles/urllib2.shtml#id5

    But if you haven’t already done much work with urllib2, now is a good time to switch to the requests library. It is much more user friendly – and to do what you ask is one line call – unlike the messy way in urllib2.

    requests.get('https://api.github.com/user', auth=('user', 'pass'))
    

    More details on how requests library can be found at: http://docs.python-requests.org/en/latest/user/quickstart/#basic-authentication

    To install requests library you only need to do:

    sudo pip install requests
    

    If you’re on windows you should drop the sudo part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I handle post request in python script? Somewhere I want to send
I want to send a POST request with Python, setting the whole POST body
I want to send messages to multiple friends in linkedin using python. from docs
I want to send a csv file from Android to Python AppEngine. I'm using
I want to send some data to an Arduino through pyserial in Python. All
I am using the Python avro library . I want to send an avro
Given: alphabet = ['a','b','c',...,'z'] i want python to enumerate every combination (starting from 1
I want to send an email with an attachment using the following code (Python
I want to send a value for User-agent while requesting a webpage using Python
I want to send email messages that have arbitrary unicode bodies in a Python

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.