473,231 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

urllib2 request htaccess page through proxy

I write this simply code that should give me the access to private page with
htaccess using a proxy, i don't known because it's wrong...
import urllib,urllib2

#input url
url="http://localhost/private/file"

#proxy set up
proxy_handler = urllib2.ProxyHandler({'http': 'http://myproxy:8888'})

#htaccess set up
user="matteo"
password="matteo"
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)

opener = urllib2.build_opener(proxy_handler,authhandler)
urllib2.install_opener(opener)

#open the url
req=urllib2.Request(url)
data=urllib2.urlopen(req).read()
print data

i get no access on access.log from apache2 and nothing from the proxy in
tcpdump log. If i use only the proxy with a page that doesn't use htaccess
it works... if anyone could help,regards...


Traceback (most recent call last):
File "proxy.py", line 22, in ?
data=urllib2.urlopen(req).read()

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 130, in urlopen
return _opener.open(url, data)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 364, in open
response = meth(req, response)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 471, in http_response
response = self.parent.error(

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 396, in error
result = self._call_chain(*args)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 337, in _call_chain
result = func(*args)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 741, in http_error_401
host, req, headers)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 720, in http_error_auth_reqed
return self.retry_http_basic_auth(host, req, realm)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 730, in retry_http_basic_auth
return self.parent.open(req)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 364, in open
response = meth(req, response)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 471, in http_response
response = self.parent.error(

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 402, in error
return self._call_chain(*args)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/urllib2.py",
line 337, in _call_chain
result = func(*args)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/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: Authorization Required


Feb 11 '07 #1
1 5713
Alessandro Fachin <Al***************@gmail.comwrites:
I write this simply code that should give me the access to private page with
htaccess using a proxy, i don't known because it's wrong...
[...]
i get no access on access.log from apache2 and nothing from the proxy in
tcpdump log. If i use only the proxy with a page that doesn't use htaccess
it works... if anyone could help,regards...
[...]
urllib2.HTTPError: HTTP Error 401: Authorization Required
Works for me (using Squid and Apache both running on localhost).
Looking at what goes over the wire, I see a 401 followed by a 299
response, which is what is expected (the 401 prompts the client to
send the username and password, which is then rewarded with the 200).

Could you describe in more detail what your proxy and Apache
configuration are like? And more about your network (on what machines
do proxy, HTTP server, and HTTP client run -- all on the same machine,
some on the same machine, all three on three different machines?) The
more detail the better.
John
Feb 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: O. Koch | last post by:
Until now, i know that ftplib doesn't support proxies and that i have to use urllib2. But i don't know how to use the urllib2 correct. I found some examples, but i don't understand them. Is...
4
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
1
by: Herman Geldenhuys | last post by:
Hey. Im trying to post some variables to an URL, but I get an error saying that my XML is parsed incorrectly. I know that it is not. At closer inspection I found out that some module in Python...
0
by: Benjamin Schollnick | last post by:
Folks, With Windows XP, and Python v2.41 I am running into a problem.... The following code gives me an unknown protocol error.... And I am not sure how to resolve it... I have a API...
1
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an...
1
by: tomazi75-nospam(at)gmail.com | last post by:
Hello all, I've a problem using urllib2 with a proxy which need authentication. I've tested the 'simple way' : -- code -- import urllib # example values for the post
3
by: itay_k | last post by:
Hi, I am running the following simple code (just open connection to some https page with proxy): proxy= '666.179.227.666:80' proxy=urllib2.ProxyHandler({"https":'https://'+proxy}) opener =...
1
by: Magnus.Moraberg | last post by:
Hi, I have the following code - import urllib2 from BeautifulSoup import BeautifulSoup proxy_support = urllib2.ProxyHandler({"http":"http:// 999.999.999.999:8080"}) opener =...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.