Python Glossary Русский

all Python 3urllib.requestfunction

urllib.request.getproxies()

cookies and proxies

Returns the scheme-to-proxy-URL dict that urllib uses by default: from the environment or from system settings.

Syntax

urllib.request.getproxies()

It first reads variables like http_proxy in any case, lowercase winning over uppercase; without them it falls back to the Windows registry or macOS settings. The no_proxy variable lands in the dict too, under the key 'no'. In a CGI environment uppercase HTTP_PROXY is ignored, since a client can inject it with a Proxy: header.

Examples

import os, urllib.request
os.environ['https_proxy'] = 'http://proxy.local:3128'
os.environ['no_proxy'] = 'localhost'
proxies = urllib.request.getproxies()
print(proxies.get('https'), proxies.get('no'))  # → http://proxy.local:3128 localhost

See also

Open in the full glossarydocs.python.orgReport an inaccuracy