def __init__(self, uri, timeout=None, ssl_context_factory=None):
"""Initialize a HTTP Socket.
@param uri(str) The http_scheme:://host:port/path to connect to.
@param timeout timeout in ms
"""
parsed = urllib.parse.urlparse(uri)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or http_client.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or http_client.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
self.__wbuf = BytesIO()
self.__http = None
self.__custom_headers = None
self.__timeout = None
if timeout:
self.setTimeout(timeout)
self._ssl_context_factory = ssl_context_factory
python类HTTPS_PORT的实例源码
def do_auth_capture(amount='0.00', card_num=None, exp_date=None,card_cvv=None):
""" function that connects to the Authorize.Net with billing information. Returns a Python list
containing the response parameters of sent back by the payment gateway.
The first item in the response list is the reponse code; the 7th item is the uniquely identifying
transaction ID
"""
delimiter = '|'
raw_params = { 'x_login': settings.AUTHNET_LOGIN,
'x_tran_key': settings.AUTHNET_KEY,
'x_type': 'AUTH_CAPTURE',
'x_amount': amount,
'x_version': '3.1',
'x_card_num': card_num,
'x_exp_date': exp_date,
'x_delim_char': delimiter,
'x_relay_response': 'FALSE',
'x_delim_data': 'TRUE',
'x_card_code': card_cvv
}
params = urllib.urlencode(raw_params)
headers = { 'content-type':'application/x-www-form-urlencoded',
'content-length':len(params) }
post_url = settings.AUTHNET_POST_URL
post_path = settings.AUTHNET_POST_PATH
cn = httplib.HTTPSConnection(post_url, httplib.HTTPS_PORT)
cn.request('POST', post_path, params, headers)
return cn.getresponse().read().split(delimiter)
def __init__(self, uri_or_host, port=None, path=None):
"""THttpClient supports two different types constructor parameters.
THttpClient(host, port, path) - deprecated
THttpClient(uri)
Only the second supports https."""
if port is not None:
warnings.warn("Please use the THttpClient('http://host:port/path') syntax", DeprecationWarning, stacklevel=2)
self.host = uri_or_host
self.port = port
assert path
self.path = path
self.scheme = 'http'
else:
parsed = urlparse.urlparse(uri_or_host)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or httplib.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or httplib.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
self.__wbuf = StringIO()
self.__http = None
self.__timeout = None
def __init__(self, uri_or_host, port=None, path=None):
if port is not None:
warnings.warn(
"Please use the THttpClient('http://host:port/path') syntax",
DeprecationWarning,
stacklevel=2)
self.host = uri_or_host
self.port = port
assert path
self.path = path
self.scheme = 'http'
else:
parsed = urlparse.urlparse(uri_or_host)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or httplib.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or httplib.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
self.__wbuf = StringIO()
self.__http = None
self.__timeout = None
self.__custom_headers = {}
def __init__(
self,
uri_or_host,
port=None,
path=None,
proxy_host=None,
proxy_port=None
):
"""THttpClient supports two different types constructor parameters.
THttpClient(host, port, path) - deprecated
THttpClient(uri)
Only the second supports https."""
"""THttpClient supports proxy
THttpClient(host, port, path, proxy_host, proxy_port) - deprecated
ThttpClient(uri, None, None, proxy_host, proxy_port)"""
if port is not None:
warnings.warn(
"Please use the THttpClient('http://host:port/path') syntax",
DeprecationWarning,
stacklevel=2)
self.host = uri_or_host
self.port = port
assert path
self.path = path
self.scheme = 'http'
else:
parsed = urlparse.urlparse(uri_or_host)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or httplib.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or httplib.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
if proxy_host is not None and proxy_port is not None:
self.endpoint_host = proxy_host
self.endpoint_port = proxy_port
self.path = urlparse.urlunparse((
self.scheme,
"%s:%i" % (self.host, self.port),
self.path,
None,
None,
None
))
else:
self.endpoint_host = self.host
self.endpoint_port = self.port
self.__wbuf = StringIO()
self.__http = None
self.__timeout = None
self.__headers = {}