本文整理匯總了Python中httplib.HTTPS屬性的典型用法代碼示例。如果您正苦於以下問題:Python httplib.HTTPS屬性的具體用法?Python httplib.HTTPS怎麽用?Python httplib.HTTPS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類httplib
的用法示例。
在下文中一共展示了httplib.HTTPS屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post_multipart
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def post_multipart(host, selector, fields, files):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
Reference: https://raw.githubusercontent.com/Gawen/virustotal/master/virustotal.py
"""
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTPS(host)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
# Reference: https://raw.githubusercontent.com/Gawen/virustotal/master/virustotal.py
示例2: redirect_internal
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if 'location' in headers:
newurl = headers['location']
elif 'uri' in headers:
newurl = headers['uri']
else:
return
void = fp.read()
fp.close()
# In case the server sent a relative URL, join with original:
newurl = basejoin(self.type + ":" + url, newurl)
# For security reasons we do not allow redirects to protocols
# other than HTTP, HTTPS or FTP.
newurl_lower = newurl.lower()
if not (newurl_lower.startswith('http://') or
newurl_lower.startswith('https://') or
newurl_lower.startswith('ftp://')):
raise IOError('redirect error', errcode,
errmsg + " - Redirection to url '%s' is not allowed" %
newurl,
headers)
return self.open(newurl)
示例3: redirect_internal
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if 'location' in headers:
newurl = headers['location']
elif 'uri' in headers:
newurl = headers['uri']
else:
return
fp.close()
# In case the server sent a relative URL, join with original:
newurl = basejoin(self.type + ":" + url, newurl)
# For security reasons we do not allow redirects to protocols
# other than HTTP, HTTPS or FTP.
newurl_lower = newurl.lower()
if not (newurl_lower.startswith('http://') or
newurl_lower.startswith('https://') or
newurl_lower.startswith('ftp://')):
raise IOError('redirect error', errcode,
errmsg + " - Redirection to url '%s' is not allowed" %
newurl,
headers)
return self.open(newurl)
示例4: test_host_port
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def test_host_port(self):
# Check invalid host_port
# Note that httplib does not accept user:password@ in the host-port.
for hp in ("www.python.org:abc", "user:password@www.python.org"):
self.assertRaises(httplib.InvalidURL, httplib.HTTP, hp)
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b",
8000),
("pypi.python.org:443", "pypi.python.org", 443),
("pypi.python.org", "pypi.python.org", 443),
("pypi.python.org:", "pypi.python.org", 443),
("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443)):
http = httplib.HTTPS(hp)
c = http._conn
if h != c.host:
self.fail("Host incorrectly parsed: %s != %s" % (h, c.host))
if p != c.port:
self.fail("Port incorrectly parsed: %s != %s" % (p, c.host))
示例5: _parse_response
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def _parse_response(self, file, sock):
# read response from input file/socket, and parse it
p, u = self.getparser()
while 1:
if sock:
response = sock.recv(1024)
else:
response = file.read(1024)
if not response:
break
if self.verbose:
sys.stdout.write("body: %s\n" % repr(response))
p.feed(response)
file.close()
p.close()
return u.close()
##
# Standard transport class for XML-RPC over HTTPS.
示例6: _parse_response
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def _parse_response(self, file, sock):
# read response from input file/socket, and parse it
p, u = self.getparser()
while 1:
if sock:
response = sock.recv(1024)
else:
response = file.read(1024)
if not response:
break
if self.verbose:
print "body:", repr(response)
p.feed(response)
file.close()
p.close()
return u.close()
##
# Standard transport class for XML-RPC over HTTPS.
示例7: post_multipart
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def post_multipart(url, fields, files):
parts = urlparse.urlparse(url)
scheme = parts[0]
host = parts[1]
selector = parts[2]
content_type, body = encode_multipart_formdata(fields, files)
if scheme == 'http':
h = httplib.HTTP(host)
elif scheme == 'https':
h = httplib.HTTPS(host)
else:
raise ValueError('unknown scheme: ' + scheme)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
示例8: build_opener
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def build_opener(*handlers):
"""Create an opener object from a list of handlers.
The opener will use several default handlers, including support
for HTTP and FTP. If there is a ProxyHandler, it must be at the
front of the list of handlers. (Yuck.)
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
"""
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
HTTPDefaultErrorHandler, HTTPRedirectHandler,
FTPHandler, FileHandler]
if hasattr(httplib, 'HTTPS'):
default_classes.append(HTTPSHandler)
skip = []
for klass in default_classes:
for check in handlers:
if inspect.isclass(check):
if issubclass(check, klass):
skip.append(klass)
elif isinstance(check, klass):
skip.append(klass)
for klass in skip:
default_classes.remove(klass)
for klass in default_classes:
opener.add_handler(klass())
for h in handlers:
if inspect.isclass(h):
h = h()
opener.add_handler(h)
return opener
示例9: https_open
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def https_open(self, req):
return self.do_open(httplib.HTTPS, req)
示例10: post_multipart
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def post_multipart(host, selector, fields, files):
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTPS(host)
h.putrequest('POST', selector)
h.putheader('Host', 'www.hybrid-analysis.com')
h.putheader('User-agent', "VxApi CLI Connector")
h.putheader('Authorization', "Basic " + vx_authorization)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
示例11: vx_check_report
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def vx_check_report(line):
re1='(.*?)'
re2='(\\|)' # DDMMYYYY 1
re3='(.*?)' # Variable Name 1
re4='(\\|)' # Any Single Character 2
re5='(.*?)' # Alphanum 1
re6='(\\|)' # Any Single Character 3
re7='(submitted)' # Word 1
rg = re.compile(re1+re2+re3+re4+re5+re6,re.IGNORECASE|re.DOTALL)
m = rg.search(line.strip())
if m:
fname = m.group(3)
alphanum=m.group(5)
# Malicious file hash for debugging purposes
# alphanum = "040c0111aef474d8b7bfa9a7caa0e06b4f1049c7ae8c66611a53fc2599f0b90f"
host = "www.hybrid-analysis.com"
selector = "https://wwww.hybrid-analysis.com/api/summary/" + alphanum + "?environmentId=100"
h = httplib.HTTPS(host)
h.putrequest('GET', selector)
h.putheader('Host', 'www.hybrid-analysis.com')
h.putheader('User-agent', "VxApi CLI Connector")
h.putheader('Authorization', "Basic " + vx_authorization)
h.endheaders()
h.send("")
errcode, errmsg, headers = h.getreply()
response = h.file.read()
response_dict = simplejson.loads(response)
vx_status = str(response_dict.get('response').get('verdict'))
if vx_status == "None":
vx_status = "https://www.hybrid-analysis.com/sample/" + alphanum + "?environmentId=100|clean"
else:
print "[*] Verdict of", fname + ":", vx_status
vx_status = "https://www.hybrid-analysis.com/sample/" + alphanum + "?environmentId=100|" + vx_status
return vx_status
示例12: open
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import HTTPS [as 別名]
def open(self):
if self.scheme == 'http':
self.__http = httplib.HTTP(self.host, self.port)
else:
self.__http = httplib.HTTPS(self.host, self.port)