Setting http proxy programmatically
Davor Cengija
dcengija_remove_ at inet.hr
Wed Mar 19 07:06:22 EST 2003
Davor Cengija wrote:
> Basically, I need to set http proxy within my program. I use
> urllib2.urlopen(url, data) to submit some form data and it works fine when
> having no proxy, or when http_proxy environment variable is set, but the
> program will be run behind a firewall which forces proxy.
>
[snip]
> Where I should instantiate ProxyHandler and/or Request and how can I force
> urllib2.urlopen() to use it?
>
Eh.. this is what happens when you're so new that you don't even know where
to start investigating :-)
However, the solution I fould doesn't work.
Here's what I have now:
def doSubmit(self, email):
self.addEmail(email)
preparedUrl = self.url + "?%s" % self.params
log(preparedUrl)
proxy = urllib2.ProxyHandler({"http" : http_proxy})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
return urllib2.urlopen(preparedUrl).info()
The program simply ignores the proxy setting and doesn't even try to
connect to it (I can read the proxy's logs). Even more, when
urllib2.install_opener(opener) is called, program ignores the http_proxy
environment variable as well.
The error I'm getting is:
<urlopen error (-3, 'Temporary failure in name resolution')>
while I expect
HTTP Error 404: WWWOFFLE Will Get
which happens when urllib2.install_opener(opener) is commented out and
http_proxy environment variable is set.
Thanks!
--
Davor Cengija, dcengija_remove_ at inet.hr
More information about the Python-list
mailing list