Reputation: 1
I want to access a web page with urllib2 and I keep getting an HTTP Error 401: Unauthorized.
Now, my problem is that this page doesn't need any authentication when using browsers like Firefox. Only when I use Google Chrome an authentication dialog pops up. Though this happens only after the page is fully loaded. So I can just cancel the authentication and use the page as normal.
Does anyone know how I can open this webpage without authentication. Thank you very much!
P.S. the pages url is: http://61.19.248.15/$sitepreview/sampran.go.th/
Upvotes: 0
Views: 4390
Reputation: 2640
I am bypassing these errors like this:
def append_text(string,n):
i=1
while i<n:
i = i+1
url = string + str(i)
try:
f = urllib.urlopen(url)
s = f.read()
...
except IOError, e:
if hasattr(e, 'code'):
print 'We got an error'
print e.code
Upvotes: 0
Reputation: 151
This is one of the best article out there on authentication.
http://www.voidspace.org.uk/python/articles/authentication.shtml
Upvotes: 1
Reputation: 23509
If the web server wants to returnin a 401 status instead of returning the web page, there is no way for a client to grab the content anyway. Instead, you must convince the server to serve the page. Perhaps it is expecting authentication credentials that you already have saved in Firefox. Perhaps it wants to see Firefox's User-Agent header in your http request. If you can't guess or ask the server admin, you might try using Wireshark to sniff the network conversation of a successful session and compare it to that of an unsuccessful one.
Upvotes: 0