473,597 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urllib2 and proxy question

urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and
wanting to test things *locally*. IE is set to not use the proxy when
fetching local adresses, but urllib2 ignores that part of the setting
and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it
to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #1
4 3511
rbt
Fuzzyman wrote:
urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and
wanting to test things *locally*. IE is set to not use the proxy when
fetching local adresses, but urllib2 ignores that part of the setting
and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it
to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml


"Alternativ ely, the optional proxies argument may be used to explicitly
specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen( some_url, proxies={})
Jul 18 '05 #2

rbt wrote:
Fuzzyman wrote:
urllib2 (under windows) will auto-detect your proxy settings and use those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and wanting to test things *locally*. IE is set to not use the proxy when fetching local adresses, but urllib2 ignores that part of the setting and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

"Alternativ ely, the optional proxies argument may be used to

explicitly specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen( some_url, proxies={})


Wikkid... I'll try that. Nice one, thanks for your help.
It *still* means I have to have a different version for testing locally
- but it's better than the alternative.
Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #3

rbt wrote:
Fuzzyman wrote:
urllib2 (under windows) will auto-detect your proxy settings and use those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and wanting to test things *locally*. IE is set to not use the proxy when fetching local adresses, but urllib2 ignores that part of the setting and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

"Alternativ ely, the optional proxies argument may be used to

explicitly specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen( some_url, proxies={})


Rats.. this answer is for urllib - *NOT* urllib2 !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #4

rbt wrote:
Fuzzyman wrote:
urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and wanting to test things *locally*. IE is set to not use the proxy when fetching local adresses, but urllib2 ignores that part of the setting and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

"Alternativ ely, the optional proxies argument may be used to

explicitly specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen( some_url, proxies={})


The correct equivalent for urllib2 (in answer to my question !) is :
proxy_support = urllib2.ProxyHa ndler({})
opener = urllib2.build_o pener(proxy_sup port)
urllib2.install _opener(opener)


which is slightly more complicated but does exactly the same job !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #5

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

Similar topics

4
21096
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
4451
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" :
0
1427
by: Lee, Dustin | last post by:
I'm using python2.2.2 on redhat linux 7.3 Here's a snippet of what I'm trying to run: # set up proxy import urllib2 proxy_support = urllib2.ProxyHandler({"http":"http://webproxy.mycompany.com:3128"}) #proxy_support = urllib2.ProxyHandler() opener = urllib2.build_opener(proxy_support) urllib2.install_opener(opener)
1
3359
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.
6
11665
by: Alejandro Dubrovsky | last post by:
I see from googling around that this is a popular topic, but I haven't seen anyone saying "ah, yes, that works", so here it goes. How does one connect through a proxy which requires basic authorisation? The following code, stolen from somewhere, fails with a 407: proxy_handler = urllib2.ProxyHandler({"http" : "http://the.proxy.address:3128"}) proxy_auth_handler = urllib2.ProxyBasicAuthHandler() proxy_auth_handler.add_password("The...
3
3075
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
5746
by: Alessandro Fachin | last post by:
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
6
3459
by: Jack | last post by:
I'm trying to use a proxy server with urllib2. So I have managed to get it to work by setting the environment variable: export HTTP_PROXY=127.0.0.1:8081 But I wanted to set it from the code. However, this does not set the proxy: httpproxy = '127.0.0.1:3129' proxy_support = urllib2.ProxyHandler({"http":"http://" + httpproxy}) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) urllib2.install_opener(opener)
1
1977
by: Larry Hale | last post by:
Since it seems I have a "unique" problem, I wonder if anyone could point me in the general/right direction for tracking down the issue and resolving it myself. See my prior post @ http://groups.google.com/group/comp.lang.python/browse_thread/thread/44775994a6b55161?hl=en# for more info. (Python 2.5.2 on Win XP 64 ==>Squid Proxy requiring Authentication ==>Internet not working.) I've looked the urllib2 source over, but am having...
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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
8035
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,...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
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
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
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.