Python Http Error 401 Unauthorized
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 of this site About Us Learn more about Stack Overflow the company Business Learn more about python urllib.error.httperror http error 401 unauthorized hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Python 3 Urllib.error.httperror Http Error 401 Unauthorized
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. python3 urllib.error.httperror: http error 401: unauthorized 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,
Httppasswordmgrwithdefaultrealm
it downloads a file and saves it. I know this 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 typeerror: 'bytes' object is not callable 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')) print(response.text) to save the file you would type with open('filename.txt','w') as fout: fout.write(response.text): (I would suggest you always set verify=True in the resquests.get() command) Here is the documentation: share|improve this answer edited Oct 30 '15 at 23:35 answered Dec 3 '13 at 22:22 Back2Basics 2,088920 ok, this gave me: 'requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:550)' any thoughts on how to deal with this? –user3063129 Dec 4 '13 at 0:04 wow! i have added "verify=False" on line 2, and i get as output "response [200]", i change my question to: how get the file after that? –user3063129 Dec 4 '13 at 0:26 I updated the post. –Back2Basics Dec 4 '13 at 7:56 add a comment| up vote 1 down vote Doesn't the browser also ask you to sign in? Then you
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Urllib2 Python
policies of this site About Us Learn more about Stack Overflow the
Urllib Python 3
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags python sharepoint unauthorized Users 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 http://stackoverflow.com/questions/20361249/http-error-401-authorization-required-while-downloading-a-file-from-https-websi takes a minute: Sign up HTTP Basic Authentication is failing in python script up vote 1 down vote favorite I am trying to connect to a REST resource and retrieve the data using Python script (Python 3.2.3). When I run the script I am getting error as HTTP Error 401: Unauthorized. Please note that I am able to access the given http://stackoverflow.com/questions/12202156/http-basic-authentication-is-failing-in-python-script REST resource using REST client using Basic Authentication. In the REST Client I have specified the hostname, user and password details (realm is not required). Below is the code and complete error. Your help is very much appreciated. Code: import urllib.request # set up authentication info auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password(realm=None, uri=r'http://hostname/', user='administrator', passwd='administrator') opener = urllib.request.build_opener(auth_handler) urllib.request.install_opener(opener) res = opener.open(r'http://hostname:9004/apollo-api/nodes') nodes = res.read() Error Traceback (most recent call last): File "C:\Python32\scripts\get-nodes.py", line 12, in
revision of this HOWTO, available at urllib2 - Le Manuel manquant. Introduction¶ Related Articles You may also find useful the following article on fetching web resources with Python: Basic Authentication https://docs.python.org/3/howto/urllib2.html A tutorial on Basic Authentication, with examples in Python. urllib.request is a Python https://github.com/calmh/unifi-api/issues/36 module for fetching URLs (Uniform Resource Locators). It offers a very simple interface, in the form of the urlopen function. This is capable of fetching URLs using a variety of different protocols. It also offers a slightly more complex interface for handling common situations - like basic authentication, cookies, proxies and so on. http error These are provided by objects called handlers and openers. urllib.request supports fetching URLs for many "URL schemes" (identified by the string before the ":" in URL - for example "ftp" is the URL scheme of "ftp://python.org/") using their associated network protocols (e.g. FTP, HTTP). This tutorial focuses on the most common case, HTTP. For straightforward situations urlopen is very easy to use. But as soon http error 401 as you encounter errors or non-trivial cases when opening HTTP URLs, you will need some understanding of the HyperText Transfer Protocol. The most comprehensive and authoritative reference to HTTP is RFC 2616. This is a technical document and not intended to be easy to read. This HOWTO aims to illustrate using urllib, with enough detail about HTTP to help you through. It is not intended to replace the urllib.request docs, but is supplementary to them. Fetching URLs¶ The simplest way to use urllib.request is as follows: import urllib.request with urllib.request.urlopen('http://python.org/') as response: html = response.read() If you wish to retrieve a resource via URL and store it in a temporary location, you can do so via the urlretrieve() function: import urllib.request local_filename, headers = urllib.request.urlretrieve('http://python.org/') html = open(local_filename) Many uses of urllib will be that simple (note that instead of an ‘http:' URL we could have used a URL starting with ‘ftp:', ‘file:', etc.). However, it's the purpose of this tutorial to explain the more complicated cases, concentrating on HTTP. HTTP is based on requests and responses - the client makes requests and servers send responses. urllib.request mirrors this with a Sign in Pricing Blog Support Search GitHub This repository Watch 54 Star 256 Fork 87 calmh/unifi-api Code Issues 9 Pull requests 5 Projects 0 Pulse Graphs New issue New issue HTTP Error 401 #36 Closed ghost opened this Issue Aug 28, 2015 · 9 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 6 participants ghost commented Aug 28, 2015 I am experiencing a HTTP Error 401. I am using the latest unifi-api and choose as version v4. My controller firmware is: v4.6.4 urllib2.HTTPError: HTTP Error 401: Unauthorized Before i updated my Controller to 4.6.4 i was on 3.x and everything was working. After i updated my Controller i changed the version from v3 to v4 when instantiating the controller and ran in this problem any idea ? Is version 4.6.4 already supported ? rapsta commented Aug 28, 2015 What meta->error, and what meta->msg is returned by the controller? v4 returns a json-object on 401-error ghost commented Sep 3, 2015 /usr/local/bin# python unifi-ls-clients -c UniFi -u admin -p 'xxxxxxxxx' -v v4 -s xxxxxxxxx Traceback (most recent call last): File "unifi-ls-clients", line 17, in aps = c.get_aps() File "/usr/local/lib/python2.7/dist-packages/unifi/controller.py", line 137, in get_aps return self._read(self.api_url + 'stat/device', params) File "/usr/local/lib/python2.7/dist-packages/unifi/controller.py", line 76, in _read res = self.opener.open(url, params) File "/usr/lib/python2.7/urllib2.py", line 437, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 550, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 475, in error return self._call_chain(args) File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(args) File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized ghost commented Sep 15, 2015 No one ? vitosans commented Oct 15, 2015 did you try changing your version to v4? oza4h07 commented Oct 23, 2015 @vitosans: I think he did change to v4: he installed v4.6.4 and added -v v4 as argument to unifi-ls-clients. Maybe you were thinking of something else ? rjt commented Feb 9, 2016 On 20160209, using the pip install -U unifi version would still result in 401 UnAuthorized. Figuring that the pip version has not been u