Python Http Error 401 Authorization Required
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Python Urllib.error.httperror Http Error 401 Unauthorized
of this site About Us Learn more about Stack Overflow the company python 3 urllib.error.httperror http error 401 unauthorized Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Python3 Urllib.error.httperror: Http Error 401: Unauthorized
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a httppasswordmgrwithdefaultrealm() minute: Sign up HTTP Basic Authentication Doesn't Seem to Work with urllib2 in python up vote 7 down vote favorite 4 I'm trying to download a page protected with basic authentication using urllib2. I'm using python 2.7 but I also tried it on another computer with python 2.5 and encountered the exact same behavior. I followed the example given in this guide python sharepoint unauthorized as closely as I could and here is the code that I produced: import urllib2 passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, "http://authenticationsite.com/', "protected", "password") authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) f = opener.open("http://authenticationsite.com/content.html") print f.read() f.close() Unfortunately the server isn't mine so I can't share the details; I swapped them out above and below. When I run it I get the following Traceback: File "/usr/lib/python2.7/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 435, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Authorization Required Now, the interesting part is when I monitor the tcp traffic on the computer using ngrep: ngrep host 74.125.224.49 interface: wlan0 (192.168.1.0/255.255.255.0) filter: (ip) and ( host 74.125.224.49 ) #### T 192.168.1.74:34366 -74.125.224.49:80 [AP] GET /content.html HTTP/1.1..Accept-Encoding: identity..Host: authenticationsite.com..Connection: close..User-Agent: Python-urllib/2.7.... ## T 74.125.224.49:80 -192.168.1.74:34366 [AP] HTTP/1.1 401 Authorization Required..Date: Sun, 27 Feb 2011 03:39:31 GMT..Server: Apache/2.2.3 (Red Hat)..WWW-Authenticate: Digest realm="protected", nonce="6NSgTzudBAA=ac585d1f7ae0632c4b90324aff5e39e0f1fc25 05", algorithm=MD5, qop="auth"..Content-Le
here for a quick overview of the site Help Center Detailed answers to any questions you might
Python Urllib2 Authentication Example
have Meta Discuss the workings and policies of this site About python requests module Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads
Python Requests Download File
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million http://stackoverflow.com/questions/5131403/http-basic-authentication-doesnt-seem-to-work-with-urllib2-in-python programmers, just like you, helping each other. Join them; it only takes a minute: Sign up HTTP Error 401: Authorization Required while downloading a file from HTTPS website and saving it up vote 0 down vote favorite Basically i need a program that given a URL, it downloads a file and saves it. I know this http://stackoverflow.com/questions/20361249/http-error-401-authorization-required-while-downloading-a-file-from-https-websi should be easy but there are a couple of drawbacks here... First, it is part of a tool I'm building at work, I have everything else besides that and the URL is HTTPS, the URL is of those you would paste in your browser and you'd get a pop up saying if you want to open or save the file (.txt). Second, I'm a beginner at this, so if there's info I'm not providing please ask me. :) I'm using Python 3.3 by the way. I tried this: import urllib.request response = urllib.request.urlopen('https://websitewithfile.com') txt = response.read() print(txt) And I get: urllib.error.HTTPError: HTTP Error 401: Authorization Required Any ideas? Thanks!! python python-3.x authentication https share|improve this question edited Oct 31 '15 at 12:37 J.F. Sebastian 182k42337492 asked Dec 3 '13 at 20:42 user3063129 312 add a comment| 4 Answers 4 active oldest votes up vote 4 down vote accepted You can do this easily with the requests library. import requests response = requests.get('https://websitewithfile.com/text.txt',verify=False, auth=('user', 'pass')
here for a quick overview of the site Help Center Detailed answers to any http://stackoverflow.com/questions/28349239/http-error-401-authorization-required-intermittent questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow http error is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up HTTP Error 401: Authorization Required intermittent up vote 0 down vote favorite This is more of a linux/security related question (than Python's urllib2 authentication question) My setup is: I am http error 401 running a Ubuntu Server in my company's corporate network I notice that when I try to access the internet via a browser (chrome or firefox), I intermittently get redirected to company's security page asking me for my company's credentials. Ubuntu server's firewall is disabled. I am not sure why, but when I try running the following script (to fetch data from internet, even google.com), this script intermittently fails due to 401 Authorization Required Error. Once this happens, then I have to open a browser (obviously access via VNC) and then go to any page and I have to enter my credentials. And once I do, then the script runs just fine for a while. And after a while, it fails due 401 error again. Script import urllib2 url = 'http://nominatim.openstreetmap.org/search.php?countrycodes=us&state=colorado&street=6900+W+25th+Ave&format=json&addressdetails=1&polygon_geojson=1' request = urllib2.Request(url) response = urllib2.urlopen(request).read() print response Traceback (most recent call last): File "/home/amit/workspace/clink/device_polling/mydb/dbmanager.py", line 1554, in _poll_device self.update__device_geoloc(deviced_alldb, mydbc, hpnac, logobj) File "/hom