Python Urllib.error.httperror 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
Python 3 Urllib.error.httperror Http Error 401 Unauthorized
more about Stack Overflow the company Business Learn more about hiring developers or posting python urllib2 401 unauthorized ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community python3 urllib.error.httperror: http error 401: unauthorized Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python: urllib2.HTTPError: HTTP Error 401: Unauthorized up vote 6 down
Httppasswordmgrwithdefaultrealm
vote favorite 2 I was trying to load a web page, but I ran into this problem. I do have the username and password, but I don't know how to use them in python code. I looked up on python tutorial, and this is what I wrote: import urllib2 password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() username = 'user' password = 'pass' top_level_url = "www.something.com:80" password_mgr.add_password(None, top_level_url, username, password) handler = urllib2.HTTPBasicAuthHandler(password_mgr)
Typeerror: 'bytes' Object Is Not Callable
opener = urllib2.build_opener(handler) opener.open('http://www.something.com/h/h.html') urllib2.install_opener(opener) response = urllib2.urlopen() page = response.read() print page Anything wrong? python authentication share|improve this question edited Apr 17 '12 at 17:44 Rup 22.7k64977 asked Apr 17 '12 at 17:18 stupidguy 136128 add a comment| 2 Answers 2 active oldest votes up vote 16 down vote Here is working code import urllib2 url = 'http://www.abc.com/index.html' username = 'user' password = 'pass' p = urllib2.HTTPPasswordMgrWithDefaultRealm() p.add_password(None, url, username, password) handler = urllib2.HTTPBasicAuthHandler(p) opener = urllib2.build_opener(handler) urllib2.install_opener(opener) page = urllib2.urlopen(url).read() share|improve this answer answered Jun 22 '12 at 18:48 big 54521429 add a comment| up vote 4 down vote I think you can use requests module which would make it be more easy for you. import requests username = 'user' password = 'pass' url = 'http://www.example.com/index.html' r = requests.get(url, auth=(username, password)) page = r.content() print page share|improve this answer answered Jul 18 '14 at 0:19 lerner adams 312313 Could be because of my python version, but just to let others know: I had to remove the parentheses on r.content() to get this to work (page = r.content). –Erlend D. Jan 22 '15 at 8:25 add a comment| Your Answer draft saved draft discarded Sign up or log i
here for a quick overview of the site Help Center Detailed answers python sharepoint unauthorized to any questions you might have Meta Discuss the workings
Urllib Python 3
and policies of this site About Us Learn more about Stack Overflow the company Business python urllib3 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 http://stackoverflow.com/questions/10195915/python-urllib2-httperror-http-error-401-unauthorized Overflow Community Stack Overflow 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: Unauthorized” when querying youtube api for playlist with python up vote 1 down vote favorite 2 I try to write a http://stackoverflow.com/questions/26451173/http-error-401-unauthorized-when-querying-youtube-api-for-playlist-with-pytho simple python3 script that gets some playlist informations via the youtube API. However I always get a 401 Error whereas it works perfectly when I enter the request string in a browser or making a request with w-get. I'm relatively new to python and I guess I'm missing some important point here. This is my script. Of course I actually use a real API-Key. from urllib.request import Request, urlopen from urllib.parse import urlencode api_key = "myApiKey" playlist_id = input('Enter playlist id: ') output_file = input('Enter name of output file (default is playlist id') if output_file == '': output_file = playlist_id url = 'https://www.googleapis.com/youtube/v3/playlistItems' params = {'part': 'snippet', 'playlistId': playlist_id, 'key': api_key, 'fields': 'items/snippet(title,description,position,resourceId/videoId),nextPageToken,pageInfo/totalResults', 'maxResults': 50, 'pageToken': '', } data = urlencode(params) request = Request(url, data.encode('utf-8')) response = urlopen(request) content = response.read() print(content) Unfortunately it rises a error at response = urlopen(request) Traceback (most recent call last): File "gpd-he
Post #1 of 4 (6406 views) Permalink Problem with urllib2 and authentification Using this script for http://forum.kodi.tv/showthread.php?tid=193572 connect to Zope I have this error ---script: import urllib2 protocolo='http://' servidor='10.28.1.239/' pagina='manage' fullurl=protocolo+servidor+pagina aut=urllib2.HTTPBasicAuthHandler() aut.add_password(realm=None, uri=servidor, user='myadmin', passwd='mypass') http error opener=urllib2.build_opener(aut, urllib2.HTTPHandler(debuglevel=1)) print opener.open(fullurl).read() ---Error: connect: (10.28.1.239, 80) send: 'GET /manage HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: 10.28.1.239\r\nConnection: close\r\nUser-agent: Python-urllib/2.4\r\n\r\n' reply: 'HTTP/1.1 401 Unauthorized\r\n' header: Server: Zope/(Zope 2.10.5-final, python 2.4.4, win32) ZServer/1.1 header: Date: Tue, 22 Apr 2008 14:14:45 GMT header: http error 401 Bobo-Exception-Line: 713 header: Content-Length: 884 header: Bobo-Exception-Value: See the server error log for details header: Content-Type: text/html; charset=iso-8859-15 header: Bobo-Exception-Type: Unauthorized header: Connection: close header: Bobo-Exception-File: HTTPResponse.py header: WWW-Authenticate: basic realm="Zope" Traceback (most recent call last): File "z.py", line 15, in ? print opener.open(fullurl).read() File "/usr/local/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/local/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/local/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/local/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/local/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized why not send authentification? I try python 2.5 on slackware 12 t
via Python [Solved] Unauthorized error when calling JSON-RPC via Python Thread Rating: 0 Vote(s) - 0 Average 1 2 3 4 5 Post Reply « Next Oldest | Next Newest» silmano Junior Member Posts: 44 Joined: Mar 2013 Reputation: 0 2014-04-30 11:56 [Solved] Unauthorized error when calling JSON-RPC via Python Post: #1 I'm starting to mess a little with JSON-RPC API, but I don't seem able to run any command. I've tried using curl with JSONRPC.Ping method, but it just executes it without any output and if I call the same method via Python script, I get a HTTP Error 401: Unauthorized. I've checked that XBMC has two ports open: 7777 (I use this one for the Android remote) and 9090. If I use the 7777 port, I get an answer right away using both curl and python. With curl I just get my prompt back (with no answer nor error) and with python I get a 401 error. If I use port 9090, the program just stays there as XBMC doesn't seem to answer from that port. I've checked XBMC options and the only one not enabled is the UPnP protocol, the others to let other computers/programs handle XBMC are enabled. The Android remote app works without issue. Any idea where could be the issue? Gaming HTPC (i5/R9 280) Windows 8.1 KODI v14 (This post was last modified: 2014-05-05 15:35 by silmano.) find quote Montellese Team Kodi Developer Posts: 4,722 Joined: Jan 2009 Reputation: 60 Location: Switzerland 2014-04-30 21:29 Post: #2 First of all you need to tell us what version of XBMC you are using. Then you need to provide a Debug log (wiki) from when you are trying to do the JSON-RPC requests. If you are using a Gotham Beta or RC you need to enable JSON-RPC logging in System -> Settings -> System -> Debugging. Last but not least you should provide the code snippet (or command) that you are executing to send the JSON-RPC request (including the exact JSON-RPC request). HTTP 401 could mean that you have specified a username and password for XBMC's webserver in which case you need to provide them with your HTTP requests. Port 9090 is a TCP server so you won't be able to send HTTP requests to it. Always read the online manual (wiki), FAQ (wiki) and search the forum before posting. Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki). Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues. find quote silmano Junior Member Posts: 44 Joined: Mar 2013