Reputation: 716
I am trying to log onto a website that throws me a "401: Authentication Required" error and then crashes. The script crashes on the urllib2.open(url)
so I cannot currently read the response. How can I get the data from this response other than the error?
Upvotes: 1
Views: 253
Reputation: 96
Take a look at http://docs.python.org/howto/urllib2.html
>>> req = urllib2.Request('http://www.python.org/fish.html')
>>> try:
>>> urllib2.urlopen(req)
>>> except HTTPError, e:
>>> print e.code
>>> print e.read()
>>>
404
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?xml-stylesheet href="./css/ht2html.css" type="text/css"?>
...... etc...
Upvotes: 1