本文整理汇总了Python中urllib.request.data方法的典型用法代码示例。如果您正苦于以下问题:Python request.data方法的具体用法?Python request.data怎么用?Python request.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib.request
的用法示例。
在下文中一共展示了request.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: urlopen
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, **_3to2kwargs):
if 'cadefault' in _3to2kwargs: cadefault = _3to2kwargs['cadefault']; del _3to2kwargs['cadefault']
else: cadefault = False
if 'capath' in _3to2kwargs: capath = _3to2kwargs['capath']; del _3to2kwargs['capath']
else: capath = None
if 'cafile' in _3to2kwargs: cafile = _3to2kwargs['cafile']; del _3to2kwargs['cafile']
else: cafile = None
global _opener
if cafile or capath or cadefault:
if not _have_ssl:
raise ValueError('SSL support not available')
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.options |= ssl.OP_NO_SSLv2
context.verify_mode = ssl.CERT_REQUIRED
if cafile or capath:
context.load_verify_locations(cafile, capath)
else:
context.set_default_verify_paths()
https_handler = HTTPSHandler(context=context, check_hostname=True)
opener = build_opener(https_handler)
elif _opener is None:
_opener = opener = build_opener()
else:
opener = _opener
return opener.open(url, data, timeout)
示例2: __init__
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def __init__(self, url, data=None, headers={},
origin_req_host=None, unverifiable=False,
method=None):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
self.full_url = unwrap(url)
self.full_url, self.fragment = splittag(self.full_url)
self.data = data
self.headers = {}
self._tunnel_host = None
for key, value in headers.items():
self.add_header(key, value)
self.unredirected_hdrs = {}
if origin_req_host is None:
origin_req_host = request_host(self)
self.origin_req_host = origin_req_host
self.unverifiable = unverifiable
self.method = method
self._parse()
示例3: http_error_407
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def http_error_407(self, url, fp, errcode, errmsg, headers, data=None,
retry=False):
"""Error 407 -- proxy authentication required.
This function supports Basic authentication only."""
if 'proxy-authenticate' not in headers:
URLopener.http_error_default(self, url, fp,
errcode, errmsg, headers)
stuff = headers['proxy-authenticate']
match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
if not match:
URLopener.http_error_default(self, url, fp,
errcode, errmsg, headers)
scheme, realm = match.groups()
if scheme.lower() != 'basic':
URLopener.http_error_default(self, url, fp,
errcode, errmsg, headers)
if not retry:
URLopener.http_error_default(self, url, fp, errcode, errmsg,
headers)
name = 'retry_proxy_' + self.type + '_basic_auth'
if data is None:
return getattr(self,name)(url, realm)
else:
return getattr(self,name)(url, realm, data)
示例4: retry_proxy_http_basic_auth
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def retry_proxy_http_basic_auth(self, url, realm, data=None):
host, selector = splithost(url)
newurl = 'http://' + host + selector
proxy = self.proxies['http']
urltype, proxyhost = splittype(proxy)
proxyhost, proxyselector = splithost(proxyhost)
i = proxyhost.find('@') + 1
proxyhost = proxyhost[i:]
user, passwd = self.get_user_passwd(proxyhost, realm, i)
if not (user or passwd): return None
proxyhost = "%s:%s@%s" % (quote(user, safe=''),
quote(passwd, safe=''), proxyhost)
self.proxies['http'] = 'http://' + proxyhost + proxyselector
if data is None:
return self.open(newurl)
else:
return self.open(newurl, data)
示例5: retry_proxy_https_basic_auth
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def retry_proxy_https_basic_auth(self, url, realm, data=None):
host, selector = splithost(url)
newurl = 'https://' + host + selector
proxy = self.proxies['https']
urltype, proxyhost = splittype(proxy)
proxyhost, proxyselector = splithost(proxyhost)
i = proxyhost.find('@') + 1
proxyhost = proxyhost[i:]
user, passwd = self.get_user_passwd(proxyhost, realm, i)
if not (user or passwd): return None
proxyhost = "%s:%s@%s" % (quote(user, safe=''),
quote(passwd, safe=''), proxyhost)
self.proxies['https'] = 'https://' + proxyhost + proxyselector
if data is None:
return self.open(newurl)
else:
return self.open(newurl, data)
示例6: send_get
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def send_get(self, uri):
return self.__send_request('GET', uri, None)
#
# Send POST
#
# Issues a POST request (write) against the API and returns the result
# (as Python dict).
#
# Arguments:
#
# uri The API method to call including parameters
# (e.g. add_case/1)
# data The data to submit as part of the request (as
# Python dict, strings must be UTF-8 encoded)
#
示例7: get_method
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def get_method(self):
"""Return a string indicating the HTTP request method."""
if self.method is not None:
return self.method
elif self.data is not None:
return "POST"
else:
return "GET"
示例8: add_data
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def add_data(self, data):
msg = "Request.add_data method is deprecated."
warnings.warn(msg, DeprecationWarning, stacklevel=1)
self.data = data
示例9: has_data
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def has_data(self):
msg = "Request.has_data method is deprecated."
warnings.warn(msg, DeprecationWarning, stacklevel=1)
return self.data is not None
示例10: _open
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def _open(self, req, data=None):
result = self._call_chain(self.handle_open, 'default',
'default_open', req)
if result:
return result
protocol = req.type
result = self._call_chain(self.handle_open, protocol, protocol +
'_open', req)
if result:
return result
return self._call_chain(self.handle_open, 'unknown',
'unknown_open', req)
示例11: get_entity_digest
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def get_entity_digest(self, data, chal):
# XXX not implemented yet
return None
示例12: open_unknown
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def open_unknown(self, fullurl, data=None):
"""Overridable interface to open unknown URL type."""
type, url = splittype(fullurl)
raise IOError('url error', 'unknown url type', type)
示例13: open_unknown_proxy
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def open_unknown_proxy(self, proxy, fullurl, data=None):
"""Overridable interface to open unknown URL type."""
type, url = splittype(fullurl)
raise IOError('url error', 'invalid proxy for %s' % type, proxy)
# External interface
示例14: open_http
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def open_http(self, url, data=None):
"""Use HTTP protocol."""
return self._open_generic_http(http_client.HTTPConnection, url, data)
示例15: http_error
# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import data [as 别名]
def http_error(self, url, fp, errcode, errmsg, headers, data=None):
"""Handle http errors.
Derived class can override this, or provide specific handlers
named http_error_DDD where DDD is the 3-digit error code."""
# First check if there's a specific handler for this error
name = 'http_error_%d' % errcode
if hasattr(self, name):
method = getattr(self, name)
if data is None:
result = method(url, fp, errcode, errmsg, headers)
else:
result = method(url, fp, errcode, errmsg, headers, data)
if result: return result
return self.http_error_default(url, fp, errcode, errmsg, headers)