473,739 Members | 11,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ProxyHa ndler({'http': 'http://myproxy:8888'})

#htaccess set up
user="matteo"
password="matte o"
passman = urllib2.HTTPPas swordMgrWithDef aultRealm()
passman.add_pas sword(None, url, user, password)
authhandler = urllib2.HTTPBas icAuthHandler(p assman)

opener = urllib2.build_o pener(proxy_han dler,authhandle r)
urllib2.install _opener(opener)

#open the url
req=urllib2.Req uest(url)
data=urllib2.ur lopen(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.ur lopen(req).read ()

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

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

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

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

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

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

File "/opt/local/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/urllib2.py",
line 720, in http_error_auth _reqed
return self.retry_http _basic_auth(hos t, req, realm)

File "/opt/local/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/urllib2.py",
line 730, in retry_http_basi c_auth
return self.parent.ope n(req)

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

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

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

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

File "/opt/local/Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/urllib2.py",
line 480, in http_error_defa ult
raise HTTPError(req.g et_full_url(), code, msg, hdrs, fp)
urllib2.HTTPErr or: HTTP Error 401: Authorization Required


Feb 11 '07 #1
1 5759
Alessandro Fachin <Al************ ***@gmail.comwr ites:
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.HTTPErr or: 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
21118
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 there anyone who can help me?
4
4461
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 python 2.3 Here is an exemple of the piece of code I use: import urllib2 #Proxy handler proxy_handler = urllib2.ProxyHandler({"http" :
2
6118
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 #80 and line # 38 are the first line offenders. --> --> -->
1
2939
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 must be screwing up my request when I try to send it. Previously the code worked fine, but the problem occured when I included the proxy/authentication code, so that must be what is messing around with my request.
0
2076
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 written for DocuShare for a non-SSL server, and I wanted to update it
1
3372
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 authenticated file I get a HTTP status code of 401 (Unauthorized access of the file being requested) I do see in the headers the Proxy-authorization and the Authorization headers being sent for the request.
1
2768
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
3082
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 = urllib2.build_opener(proxy) request = urllib2.Request('https://somehttpspage....') response = opener.open(request)
1
3372
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 = urllib2.build_opener(proxy_support)
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.