Hi all,

Is there any module for undefining proxy for https in python like

$agent->proxy( 'https', undef ); in perl

Dani AI

Generated

If you are calling browser.open(url), that looks like mechanize. In mechanize (built on urllib2), proxies are controlled by a ProxyHandler, so you disable or override them per-scheme. To drop HTTPS proxying while keeping other schemes as-is, give the browser an explicit proxy mapping that omits https. To disable all proxies, pass an empty dict. See mechanize’s docs for details [https://mechanize.readthedocs.io/en/latest/].

import mechanize

br = mechanize.Browser()

# Disable all proxies (ignores env like HTTPS_PROXY/https_proxy)
br.set_proxies({})

# Or: keep HTTP proxy but disable HTTPS
br.set_proxies({'http': 'http://proxy.example:3128'})

resp = br.open('https://example.com/')

If you are using plain urllib2 under the hood, build an opener with a custom ProxyHandler. Passing {} disables proxies entirely for that opener. Supplying only http ensures https is not proxied (environment variables will not be consulted when you provide an explicit mapping). Reference: urllib2 ProxyHandler and proxy behavior [https://docs.python.org/2/library/urllib2.html].

import urllib2, os

# Option A: disable only HTTPS proxy for this process (env-based)
for k in ('HTTPS_PROXY', 'https_proxy'):
    os.environ.pop(k, None)
opener = urllib2.build_opener(urllib2.ProxyHandler())
resp = opener.open('https://example.com/')

# Option B: disable all proxies for this opener
# opener = urllib2.build_opener(urllib2.ProxyHandler({}))

# Option C: keep HTTP proxy but disable HTTPS
# opener = urllib2.build_opener(urllib2.ProxyHandler({'http': 'http://proxy.example:3128'}))

Tip: if you only want to bypass the proxy for specific hosts, set NO_PROXY/no_proxy to a comma-separated list like localhost,127.0.0.1,.example.com before creating the opener. If you really are on httplib as asked, you would simply connect directly to the target host (no ProxyHandler involved), and no proxy would be used.

Recommended Answers

All 2 Replies

Hm. Are you using httplib to make your connection?

Jeff

Hi ,

Yes I am using broeser.open(url) to open the site

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.