本文整理汇总了Python中httplib.HTTPSConnection方法的典型用法代码示例。如果您正苦于以下问题:Python httplib.HTTPSConnection方法的具体用法?Python httplib.HTTPSConnection怎么用?Python httplib.HTTPSConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib
的用法示例。
在下文中一共展示了httplib.HTTPSConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_optional_args
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def validate_optional_args(args):
"""Check if an argument was provided that depends on a module that may
not be part of the Python standard library.
If such an argument is supplied, and the module does not exist, exit
with an error stating which module is missing.
"""
optional_args = {
'json': ('json/simplejson python module', json),
'secure': ('SSL support', HTTPSConnection),
}
for arg, info in optional_args.items():
if getattr(args, arg, False) and info[1] is None:
raise SystemExit('%s is not installed. --%s is '
'unavailable' % (info[0], arg))
示例2: _dispatch_request
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def _dispatch_request(self, path, body):
"""Proxies GET request to discovery service API.
Args:
path: A string containing the URL path relative to discovery service.
body: A string containing the HTTP POST request body.
Returns:
HTTP response body or None if it failed.
"""
full_path = self._DISCOVERY_API_PATH_PREFIX + path
headers = {'Content-type': 'application/json'}
connection = httplib.HTTPSConnection(self._DISCOVERY_PROXY_HOST)
try:
connection.request('POST', full_path, body, headers)
response = connection.getresponse()
response_body = response.read()
if response.status != 200:
logging.error('Discovery API proxy failed on %s with %d.\r\n'
'Request: %s\r\nResponse: %s',
full_path, response.status, body, response_body)
return None
return response_body
finally:
connection.close()
示例3: get_static_file
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def get_static_file(self, path):
"""Returns static content via a GET request.
Args:
path: A string containing the URL path after the domain.
Returns:
A tuple of (response, response_body):
response: A HTTPResponse object with the response from the static
proxy host.
response_body: A string containing the response body.
"""
connection = httplib.HTTPSConnection(self._STATIC_PROXY_HOST)
try:
connection.request('GET', path, None, {})
response = connection.getresponse()
response_body = response.read()
finally:
connection.close()
return response, response_body
示例4: _DispatchRequest
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def _DispatchRequest(self, path, body):
"""Proxies GET request to discovery service API.
Args:
path: URL path relative to discovery service.
body: HTTP POST request body.
Returns:
HTTP response body or None if it failed.
"""
full_path = self._DISCOVERY_API_PATH_PREFIX + path
headers = {'Content-type': 'application/json'}
connection = httplib.HTTPSConnection(self._DISCOVERY_PROXY_HOST)
try:
connection.request('POST', full_path, body, headers)
response = connection.getresponse()
response_body = response.read()
if response.status != 200:
logging.error('Discovery API proxy failed on %s with %d.\r\n'
'Request: %s\r\nResponse: %s',
full_path, response.status, body, response_body)
return None
return response_body
finally:
connection.close()
示例5: GetStaticFile
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def GetStaticFile(self, path):
"""Returns static content via a GET request.
Args:
path: URL path after the domain.
Returns:
Tuple of (response, response_body):
response: HTTPResponse object.
response_body: Response body as string.
"""
connection = httplib.HTTPSConnection(self._STATIC_PROXY_HOST)
try:
connection.request('GET', path, None, {})
response = connection.getresponse()
response_body = response.read()
finally:
connection.close()
return response, response_body
示例6: __init__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def __init__(self, target):
# Target comes as protocol://target:port/path
self.target = target
proto, host, path = target.split(':')
host = host[2:]
self.path = '/' + path.split('/', 1)[1]
if proto.lower() == 'https':
#Create unverified (insecure) context
try:
uv_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
self.session = HTTPSConnection(host,context=uv_context)
except AttributeError:
#This does not exist on python < 2.7.11
self.session = HTTPSConnection(host)
else:
self.session = HTTPConnection(host)
self.lastresult = None
示例7: test_host_port
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def test_host_port(self):
# Check invalid host_port
for hp in ("www.python.org:abc", "user:password@www.python.org"):
self.assertRaises(httplib.InvalidURL, httplib.HTTPSConnection, hp)
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
"fe80::207:e9ff:fe9b", 8000),
("www.python.org:443", "www.python.org", 443),
("www.python.org:", "www.python.org", 443),
("www.python.org", "www.python.org", 443),
("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443),
("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b",
443)):
c = httplib.HTTPSConnection(hp)
self.assertEqual(h, c.host)
self.assertEqual(p, c.port)
示例8: read
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def read(self, url):
self.url = url
u = urlparse.urlparse(url)
self.domain = u.netloc
try:
connection = httplib.HTTPConnection(u.netloc) if u.scheme == 'http' else httplib.HTTPSConnection(u.netloc)
connection.request("GET",u.geturl(), headers=REQUEST_HEADERS)
response = connection.getresponse()
except:
self.error = "cannot read url"
return
try:
r = response.read()
except:
self.error = "cannot read"
return
self.id = bitcoin.sha256(r)[0:16].encode('hex')
filename = os.path.join(self.dir_path, self.id)
with open(filename,'w') as f:
f.write(r)
return self.parse(r)
示例9: do_buy
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def do_buy(credentials, amount):
conn = httplib.HTTPSConnection('coinbase.com')
credentials.authorize(conn)
params = {
'qty': float(amount)/SATOSHIS_PER_BTC,
'agree_btc_amount_varies': False
}
resp = conn.auth_request('POST', '/api/v1/buys', urlencode(params), None)
if resp.status != 200:
message(_('Error, could not buy bitcoin'))
return
content = json.loads(resp.read())
if content['success']:
message(_('Success!\n') + content['transfer']['description'])
else:
if content['errors']:
message(_('Error: ') + string.join(content['errors'], '\n'))
else:
message(_('Error, could not buy bitcoin'))
示例10: main
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def main(args):
"""Request a Google ID token using a JWT."""
params = urllib.urlencode({
'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion': generate_jwt(args)})
headers = {"Content-Type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPSConnection("www.googleapis.com")
conn.request("POST", "/oauth2/v4/token", params, headers)
res = json.loads(conn.getresponse().read())
conn.close()
return res['id_token']
示例11: __init__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def __init__(
self,
host,
port=None,
key_file=None,
cert_file=None,
strict=None,
timeout=None,
proxy_info=None,
ca_certs=None,
disable_ssl_certificate_validation=False,
ssl_version=None,
):
httplib.HTTPSConnection.__init__(
self,
host,
port=port,
key_file=key_file,
cert_file=cert_file,
strict=strict,
timeout=timeout,
)
self._fetch = _new_fixed_fetch(not disable_ssl_certificate_validation)
# Use a different connection object for Google App Engine Standard Environment.
示例12: paste
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def paste(self, content, lexer=None, ttl=None, key=None):
"""Create a new paste.
Args:
content: string of text to paste
lexer: lexer to use (defaults to text)
ttl: time-to-live in days (defaults to 30)
key: encrypt paste with this key; if not specified, paste is not
encrypted
Returns:
Paste object
"""
if lexer is None:
lexer = DEFAULT_LEXER
if ttl is None:
ttl = DEFAULT_TTL
if self._scheme == "https":
self._conn = httplib.HTTPSConnection(self._netloc)
else:
self._conn = httplib.HTTPConnection(self._netloc)
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
params = {"lexer": lexer,
"content": content,
"ttl": int(ttl * 86400)}
if key is not None:
params["encrypt"] = "checked"
params["key"] = key
self._lock.acquire()
self._conn.request("POST", "/submit", urllib.urlencode(params), headers)
response = self._conn.getresponse()
self._lock.release()
return self._make_paste(response, content, lexer)
示例13: __init__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
示例14: prepare_discovery_request
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def prepare_discovery_request(self, status_code, body):
self.mox.StubOutWithMock(httplib.HTTPSConnection, 'request')
self.mox.StubOutWithMock(httplib.HTTPSConnection, 'getresponse')
self.mox.StubOutWithMock(httplib.HTTPSConnection, 'close')
httplib.HTTPSConnection.request(mox.IsA(basestring), mox.IsA(basestring),
mox.IgnoreArg(), mox.IsA(dict))
httplib.HTTPSConnection.getresponse().AndReturn(
test_utils.MockConnectionResponse(status_code, body))
httplib.HTTPSConnection.close()
示例15: __init__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import HTTPSConnection [as 别名]
def __init__(self, proxytype, proxyaddr, proxyport = None, rdns = True, username = None, password = None, *args, **kwargs):
self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
httplib.HTTPSConnection.__init__(self, *args, **kwargs)