本文整理汇总了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)