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 8613031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:46:21+00:00 2026-06-12T04:46:21+00:00

I’m using URLlib2 (and python 2.7) to grab some content from a website. So

  • 0

I’m using URLlib2 (and python 2.7) to grab some content from a website. So far I have been using URLlib2 OK to get content OK, but this is the first time I’ve hit a website that has a password at the content level. I have a legit u:p (that I obviously can’t share here) and it seems like I’m not giving the right credential somehow to my request.

I’ve used the method here: Python urllib2, basic HTTP authentication, and tr.im replacing (username, password) with my credentials as a string (“myUsername”,”myPassword”)

When I print result.read() I get a blank line, and when I try print result.headers() I get:

<addinfourl at 40895752L whose fp = <socket._fileobject object at 0x00000000026757C8>>

as example, for every expected instance of the call, which I assume to mean there is a file object there of sorts…

I tried print result.info() to see if there was a header coming back, and I see a set of headers:

REDACTED
Date: Mon, 01 Oct 2012 10:06:24 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.1.6
Set-Cookie: OJSSID=mc7u47e674jmpjgk3kspfgc9l3; path=/
Refresh: 0; url=http:REDACTED loginMessage=reader.subscriptionRequiredLoginText
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8

So I can take from “loginMessage=reader.subscriptionRequiredLoginText” that I’ve not sent the credentials properly.

Any pointers?

The calling code is:

def getArticle(newLink):
request = urllib2.Request(newLink)
base64string = base64.encodestring('%s:%s' % ("myUsername", "myPassword")).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
result = urllib2.urlopen(request)
print result.read()

and an example URL is: REDACTED – its not my website!

  • 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-12T04:46:22+00:00Added an answer on June 12, 2026 at 4:46 am

    You’ll find dealing with the requests library much nicer than urllib2.

    Looking at the link you provided, it doesn’t require Basic Auth, rather, it’s a form… So you need to take the URL of the ‘action’ attribute of the form, and submit data to that. An example using requests:

    import requests
    url = 'http://www.content.alternative.ac.nz/index.php/alternative/login/signIn'
    r = requests.post(url, data={'username': 'username', 'password': 'password', 'remember': '1'})
    

    This I can’t check fully (as I don’t have a valid u&p), but by sending effectively ticking the “Remember Me” button, you should then get a cookie accessible via r.cookies which hopefully means that can be used for further requests such as:

    cookies = r.cookies
    r = requests.get('http://www.content.alternative.ac.nz/index.php/alternative/article/view/176/202', cookies=cookies)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.