本文整理汇总了Python中urllib.getproxies方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.getproxies方法的具体用法?Python urllib.getproxies怎么用?Python urllib.getproxies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.getproxies方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def __init__(self):
self.session = requests.session()
try:
self.session.proxies = urllib.getproxies() #py2
except:
self.session.proxies = urllib.request.getproxies() #py3
self.headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"X-Robinhood-API-Version": "1.0.0",
"Connection": "keep-alive",
"User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
}
self.session.headers = self.headers
示例2: find_proxy
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def find_proxy(url):
scheme, netloc, path, pars, query, fragment = urlparse.urlparse(url)
proxies = urllib.getproxies()
proxyhost = None
if scheme in proxies:
if '@' in netloc:
sidx = netloc.find('@') + 1
else:
sidx = 0
eidx = netloc.find(':')
if eidx == -1:
eidx = len(netloc)
host = netloc[sidx:eidx]
if not (host == '127.0.0.1' or urllib.proxy_bypass(host)):
proxyurl = proxies[scheme]
proxyelems = urlparse.urlparse(proxyurl)
proxyhost = proxyelems[1]
if DEBUG:
print >> sys.stderr, 'find_proxy: Got proxies', proxies, 'selected', proxyhost, 'URL was', url
return proxyhost
示例3: getProxyMap
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def getProxyMap(cfg):
"""
Return the proxyMap, or create it from old-style proxy/conaryProxy
entries.
"""
if cfg.proxyMap:
return cfg.proxyMap
# This creates a new proxyMap instance. We don't want to override the
# config's proxyMap, since old consumers of the API may modify the settings
# in-place and expect the changes to take effect.
proxyDict = urllib.getproxies()
proxyDict.update(cfg.proxy)
if hasattr(cfg, 'conaryProxy'):
for scheme, url in cfg.conaryProxy.items():
if url.startswith('http:'):
url = 'conary:' + url[5:]
elif url.startswith('https:'):
url = 'conarys:' + url[6:]
proxyDict[scheme] = url
return proxy_map.ProxyMap.fromDict(proxyDict)
# These are regrettably part of the module's published API
# pyflakes=ignore
示例4: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def __init__(self, username, password):
self.session = requests.session()
self.session.proxies = urllib.getproxies()
self.username = username
self.password = password
self.headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"X-Robinhood-API-Version": "1.0.0",
"Connection": "keep-alive",
"User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
}
self.session.headers = self.headers
self.login()
## set account url
acc = self.get_account_number()
self.account_url = self.endpoints['accounts'] + acc + "/"
示例5: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def __init__(self, proxies=None):
if proxies is None:
proxies = getproxies()
assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
self.proxies = proxies
for type, url in proxies.items():
setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
示例6: _get_proxies
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def _get_proxies(self):
proxies = getproxies()
proxy = {}
if self.proxy:
parsed_proxy = urlparse(self.proxy)
proxy[parsed_proxy.scheme] = parsed_proxy.geturl()
proxies.update(proxy)
return proxies
示例7: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def __init__(self, username=None, password=None, url=None, timeout=None, retries=None, proxy_url=None, eph_token=None, identity_domain=None):
"""Create a new client.
The *username* and *password* parameters specify the credentials to use
when connecting to the API. When the organization of the user has an identity domain,
the user must specify it or include it in the username: <identity_domain>/<username>.
When the organization doesnt have an identity domain use only the username.
The *timeout* and *retries* parameters
specify the default network system call time timeout and maximum number
of retries respectively.
*proxy_url* should be used when an HTTP proxy is in place.
*eph_token* is ephemeral access token to be used instead of username/password.
"""
self._identity_domain = identity_domain
self._username = username
self._password = password
self.timeout = timeout if timeout is not None else self.default_timeout
self.retries = retries if retries is not None else self.default_retries
self.redirects = self.default_redirects
self._logger = logging.getLogger('ravello')
self._autologin = True
self._connection = None
self._user_info = None
self._set_url(url or self.default_url)
# Get proxy setting from environment variables
try:
self._proxies = urllib.getproxies()
except:
self._proxies = urllib.request.getproxies()
if proxy_url is not None:
self._proxies = {"http": proxy_url, "https": proxy_url}
self._eph_token = eph_token
示例8: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def __init__(self, proxies=None, proxy_bypass=None):
if proxies is None:
proxies = getproxies()
assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
self.proxies = proxies
for type, url in proxies.items():
setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
if proxy_bypass is None:
proxy_bypass = urllib.proxy_bypass
self._proxy_bypass = proxy_bypass
示例9: get_soap_client
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def get_soap_client(wsdlurl, timeout=30): # pragma: no cover (not part of normal test suite)
"""Get a SOAP client for performing requests. The client is cached. The
timeout is in seconds."""
# this function isn't automatically tested because the functions using
# it are not automatically tested
if (wsdlurl, timeout) not in _soap_clients:
# try zeep first
try:
from zeep.transports import Transport
transport = Transport(timeout=timeout)
from zeep import CachingClient
client = CachingClient(wsdlurl, transport=transport).service
except ImportError:
# fall back to non-caching zeep client
try:
from zeep import Client
client = Client(wsdlurl, transport=transport).service
except ImportError:
# other implementations require passing the proxy config
try:
from urllib import getproxies
except ImportError:
from urllib.request import getproxies
# fall back to suds
try:
from suds.client import Client
client = Client(
wsdlurl, proxy=getproxies(), timeout=timeout).service
except ImportError:
# use pysimplesoap as last resort
try:
from pysimplesoap.client import SoapClient
client = SoapClient(
wsdl=wsdlurl, proxy=getproxies(), timeout=timeout)
except ImportError:
raise ImportError(
'No SOAP library (such as zeep) found')
_soap_clients[(wsdlurl, timeout)] = client
return _soap_clients[(wsdlurl, timeout)]
示例10: fromEnvironment
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def fromEnvironment(cls):
return cls.fromDict(urllib.getproxies())
示例11: get_soap_client
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import getproxies [as 别名]
def get_soap_client(wsdlurl): # pragma: no cover (not part of normal test suite)
"""Get a SOAP client for performing requests. The client is cached."""
# this function isn't automatically tested because the functions using
# it are not automatically tested
if wsdlurl not in _soap_clients:
# try zeep first
try:
from zeep import CachingClient
client = CachingClient(wsdlurl).service
except ImportError:
# fall back to non-caching zeep client
try:
from zeep import Client
client = Client(wsdlurl).service
except ImportError:
# other implementations require passing the proxy config
try:
from urllib import getproxies
except ImportError:
from urllib.request import getproxies
# fall back to suds
try:
from suds.client import Client
client = Client(wsdlurl, proxy=getproxies()).service
except ImportError:
# use pysimplesoap as last resort
from pysimplesoap.client import SoapClient
client = SoapClient(wsdl=wsdlurl, proxy=getproxies())
_soap_clients[wsdlurl] = client
return _soap_clients[wsdlurl]