本文整理汇总了Python中pycurl.SSL_VERIFYHOST属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.SSL_VERIFYHOST属性的具体用法?Python pycurl.SSL_VERIFYHOST怎么用?Python pycurl.SSL_VERIFYHOST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.SSL_VERIFYHOST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def request(self, endpoint, headers=None, post=None, first=True):
buffer = BytesIO()
ch = pycurl.Curl()
ch.setopt(pycurl.URL, endpoint)
ch.setopt(pycurl.USERAGENT, self.userAgent)
ch.setopt(pycurl.WRITEFUNCTION, buffer.write)
ch.setopt(pycurl.FOLLOWLOCATION, True)
ch.setopt(pycurl.HEADER, True)
if headers:
ch.setopt(pycurl.HTTPHEADER, headers)
ch.setopt(pycurl.VERBOSE, self.debug)
ch.setopt(pycurl.SSL_VERIFYPEER, False)
ch.setopt(pycurl.SSL_VERIFYHOST, False)
ch.setopt(pycurl.COOKIEFILE, self.settingsPath + self.username + '-cookies.dat')
ch.setopt(pycurl.COOKIEJAR, self.settingsPath + self.username + '-cookies.dat')
if post:
import urllib
ch.setopt(pycurl.POST, len(post))
ch.setopt(pycurl.POSTFIELDS, urllib.urlencode(post))
ch.perform()
resp = buffer.getvalue()
header_len = ch.getinfo(pycurl.HEADER_SIZE)
header = resp[0: header_len]
body = resp[header_len:]
ch.close()
if self.debug:
import urllib
print("REQUEST: " + endpoint)
if post is not None:
if not isinstance(post, list):
print('DATA: ' + urllib.unquote_plus(json.dumps(post)))
print("RESPONSE: " + body + "\n")
return [header, json_decode(body)]
示例2: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def request(self, method, url, headers, post_data=None):
s = util.StringIO.StringIO()
curl = pycurl.Curl()
if method == 'get':
curl.setopt(pycurl.HTTPGET, 1)
elif method == 'post':
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, post_data)
else:
curl.setopt(pycurl.CUSTOMREQUEST, method.upper())
# pycurl doesn't like unicode URLs
curl.setopt(pycurl.URL, util.utf8(url))
curl.setopt(pycurl.WRITEFUNCTION, s.write)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 80)
curl.setopt(pycurl.HTTPHEADER, ['%s: %s' % (k, v)
for k, v in headers.iteritems()])
if self._verify_ssl_certs:
curl.setopt(pycurl.CAINFO, os.path.join(
os.path.dirname(__file__), 'data/ca-certificates.crt'))
else:
curl.setopt(pycurl.SSL_VERIFYHOST, False)
try:
curl.perform()
except pycurl.error, e:
self._handle_request_error(e)
示例3: __init__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def __init__(self, url, params, bind, timeout, allow_redirects, headers, verify_keys):
"""Constructor"""
self.curl = pycurl.Curl()
full_url = url if params is None else "%s?%s" % (url, urllib.urlencode(params))
self.curl.setopt(pycurl.URL, str(full_url))
if bind is not None:
self.curl.setopt(pycurl.INTERFACE, str(bind))
self.curl.setopt(pycurl.FOLLOWLOCATION, allow_redirects)
if headers is not None:
self.curl.setopt(pycurl.HTTPHEADER, [
"%s: %s" % (str(key), str(value))
for (key, value) in headers.items()
])
if timeout is not None:
self.curl.setopt(pycurl.TIMEOUT_MS, int(timeout * 1000.0))
self.curl.setopt(pycurl.SSL_VERIFYHOST, verify_keys)
self.curl.setopt(pycurl.SSL_VERIFYPEER, verify_keys)
self.buf = StringIO.StringIO()
self.curl.setopt(pycurl.WRITEFUNCTION, self.buf.write)
示例4: connect
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def connect(self, host, port, scheme):
fp = pycurl.Curl()
fp.setopt(pycurl.SSL_VERIFYPEER, 0)
fp.setopt(pycurl.SSL_VERIFYHOST, 0)
fp.setopt(pycurl.HEADER, 1)
fp.setopt(pycurl.USERAGENT, 'Mozilla/5.0')
fp.setopt(pycurl.NOSIGNAL, 1)
return TCP_Connection(fp)
示例5: head
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def head(self):
conn = pycurl.Curl()
conn.setopt(pycurl.SSL_VERIFYPEER, False)
conn.setopt(pycurl.SSL_VERIFYHOST, 0)
conn.setopt(pycurl.URL, self.completeUrl)
conn.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD
conn.setopt(pycurl.WRITEFUNCTION, self.header_callback)
conn.perform()
rp = Response()
rp.parseResponse(self.__performHead)
self.response = rp
示例6: secure_download
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def secure_download(url, cainfo=""):
import pycurl
import io
c = pycurl.Curl()
c.setopt(pycurl.URL, url.encode("ascii"))
# -k / --insecure
# c.setopt(pycurl.SSL_VERIFYPEER, 0)
# Verify certificate
c.setopt(pycurl.SSL_VERIFYPEER, 1)
# Verify CommonName or Subject Alternate Name
c.setopt(pycurl.SSL_VERIFYHOST, 2)
# --cacert
if cainfo:
c.setopt(pycurl.CAINFO, cainfo)
res = io.StringIO()
c.setopt(pycurl.WRITEFUNCTION, res.write)
# follow up to 10 http location: headers
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 10)
c.perform()
c.close()
data = res.getvalue()
res.close()
return data
示例7: test_secure_download
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def test_secure_download(self):
import pycurl
import io
# Required mocks
mock_curl_instance = Mock()
mock_stringio_instance = Mock()
mock_stringio_instance.getvalue.return_value = "mock StringIO value"
# Expected pycurl setopt calls
expected_setopt_calls = [
call(pycurl.URL, b"https://example.com/file.extension"),
call(pycurl.SSL_VERIFYPEER, 1),
call(pycurl.SSL_VERIFYHOST, 2),
call(pycurl.CAINFO, "/etc/certs/cabundle.pem"),
call(pycurl.WRITEFUNCTION, mock_stringio_instance.write),
call(pycurl.FOLLOWLOCATION, 1),
call(pycurl.MAXREDIRS, 10),
]
with patch.object(pycurl, "Curl") as mock_curl_constructor:
with patch.object(io, "StringIO") as mock_stringio_constructor:
mock_curl_constructor.return_value = mock_curl_instance
mock_stringio_constructor.return_value = mock_stringio_instance
secure_download_result = helpers.secure_download(
"https://example.com/file.extension", "/etc/certs/cabundle.pem"
)
# Check curl calls
mock_curl_instance.setopt.assert_has_calls(expected_setopt_calls)
mock_curl_instance.perform.assert_called_once_with()
mock_curl_instance.close.assert_called_once_with()
# Check StringIO call
mock_stringio_instance.getvalue.assert_called_once_with()
self.assertEqual(secure_download_result, "mock StringIO value")
示例8: test_secure_download_no_cainfo
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def test_secure_download_no_cainfo(self):
import pycurl
import io
# Required mocks
mock_curl_instance = Mock()
mock_stringio_instance = Mock()
mock_stringio_instance.getvalue.return_value = "mock StringIO value"
mock_stringio_instance.getvalue.return_value = "mock StringIO value"
expected_setopt_calls = [
call(pycurl.URL, b"https://example.com/file.extension"),
call(pycurl.SSL_VERIFYPEER, 1),
call(pycurl.SSL_VERIFYHOST, 2),
call(pycurl.WRITEFUNCTION, mock_stringio_instance.write),
call(pycurl.FOLLOWLOCATION, 1),
call(pycurl.MAXREDIRS, 10),
]
with patch.object(pycurl, "Curl") as mock_curl_constructor:
with patch.object(io, "StringIO") as mock_stringio_constructor:
mock_curl_constructor.return_value = mock_curl_instance
mock_stringio_constructor.return_value = mock_stringio_instance
secure_download_result = helpers.secure_download(
"https://example.com/file.extension"
)
# Check curl calls
mock_curl_instance.setopt.assert_has_calls(expected_setopt_calls)
mock_curl_instance.perform.assert_called_once_with()
mock_curl_instance.close.assert_called_once_with()
# Check StringIO call
mock_stringio_instance.getvalue.assert_called_once_with()
self.assertEqual(secure_download_result, "mock StringIO value")
示例9: getPage
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def getPage (self, url, requestHeader = []) :
resultFormate = StringIO.StringIO()
fakeIp = self.fakeIp()
requestHeader.append('CLIENT-IP:' + fakeIp)
requestHeader.append('X-FORWARDED-FOR:' + fakeIp)
try:
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url.strip())
curl.setopt(pycurl.ENCODING, 'gzip,deflate')
curl.setopt(pycurl.HEADER, 1)
curl.setopt(pycurl.TIMEOUT, 120)
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
curl.setopt(pycurl.SSL_VERIFYHOST, 0)
curl.setopt(pycurl.HTTPHEADER, requestHeader)
curl.setopt(pycurl.WRITEFUNCTION, resultFormate.write)
curl.perform()
headerSize = curl.getinfo(pycurl.HEADER_SIZE)
curl.close()
header = resultFormate.getvalue()[0 : headerSize].split('\r\n')
body = resultFormate.getvalue()[headerSize : ]
except Exception, e:
header = ''
body = ''
示例10: __init__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def __init__(self, url):
self.c = pycurl.Curl()
self.headers = {}
self.c.setopt(self.c.URL, url)
if use_cert_authority:
self.c.setopt(pycurl.CAINFO, CA_PATH)
self.c.setopt(pycurl.CAPATH, CA_PATH)
#self.c.setopt(pycurl.CA_BUNDLE, CA_PATH)
else:
self.c.setopt(pycurl.SSL_VERIFYHOST, 0)
self.c.setopt(pycurl.SSL_VERIFYPEER, 0)
if http_bindaddr:
self.c.setopt(self.c.INTERFACE, http_bindaddr)
if user_agent:
self.c.setopt(pycurl.USERAGENT, user_agent)
if use_compression:
if _pycurl_compression:
# If a zero-length string is set, then an Accept-Encoding header
# containing all supported encodings is sent.
self.c.setopt(pycurl.ENCODING, "")
# someday, gzip manually with GzipFile
#else:
# self.add_header("Accept-Encoding", "gzip")
if timeout:
self.c.setopt(self.c.TIMEOUT, timeout)
if connect_timeout:
self.c.setopt(self.c.CONNECTTIMEOUT, timeout)
if max_connects:
self.c.setopt(self.c.MAXCONNECTS, max_connects)
示例11: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def request(self, url, method, body, headers):
c = pycurl.Curl()
c.setopt(pycurl.URL, str(url))
if 'proxy_host' in self.proxy:
c.setopt(pycurl.PROXY, self.proxy['proxy_host'])
if 'proxy_port' in self.proxy:
c.setopt(pycurl.PROXYPORT, self.proxy['proxy_port'])
if 'proxy_user' in self.proxy:
c.setopt(pycurl.PROXYUSERPWD, "%(proxy_user)s:%(proxy_pass)s" % self.proxy)
self.buf = StringIO()
c.setopt(pycurl.WRITEFUNCTION, self.buf.write)
#c.setopt(pycurl.READFUNCTION, self.read)
#self.body = StringIO(body)
#c.setopt(pycurl.HEADERFUNCTION, self.header)
if self.cacert:
c.setopt(c.CAINFO, str(self.cacert))
c.setopt(pycurl.SSL_VERIFYPEER, self.cacert and 1 or 0)
c.setopt(pycurl.SSL_VERIFYHOST, self.cacert and 2 or 0)
c.setopt(pycurl.CONNECTTIMEOUT, self.timeout/6)
c.setopt(pycurl.TIMEOUT, self.timeout)
if method=='POST':
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, body)
if headers:
hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()]
##print hdrs
c.setopt(pycurl.HTTPHEADER, hdrs)
c.perform()
##print "pycurl perform..."
c.close()
return {}, self.buf.getvalue()
示例12: __init__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def __init__(self, base_url="", fakeheaders=[]):
self.handle = pycurl.Curl()
# These members might be set.
self.set_url(base_url)
self.verbosity = 0
self.fakeheaders = fakeheaders
# Nothing past here should be modified by the caller.
self.payload = None
self.payload_io = BytesIO()
self.hrd = ""
# Verify that we've got the right site; harmless on a non-SSL connect.
self.set_option(pycurl.SSL_VERIFYHOST, 2)
# Follow redirects in case it wants to take us to a CGI...
self.set_option(pycurl.FOLLOWLOCATION, 1)
self.set_option(pycurl.MAXREDIRS, 5)
self.set_option(pycurl.NOSIGNAL, 1)
# Setting this option with even a nonexistent file makes libcurl
# handle cookie capture and playback automatically.
self.set_option(pycurl.COOKIEFILE, "/dev/null")
# Set timeouts to avoid hanging too long
self.set_timeout(30)
# Use password identification from .netrc automatically
self.set_option(pycurl.NETRC, 1)
self.set_option(pycurl.WRITEFUNCTION, self.payload_io.write)
def header_callback(x):
self.hdr += x.decode('ascii')
self.set_option(pycurl.HEADERFUNCTION, header_callback)
示例13: head
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def head(self):
conn=pycurl.Curl()
conn.setopt(pycurl.SSL_VERIFYPEER,False)
conn.setopt(pycurl.SSL_VERIFYHOST,1)
conn.setopt(pycurl.URL,self.completeUrl)
conn.setopt(pycurl.HEADER, True) # estas dos lineas son las que importan
conn.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD
conn.setopt(pycurl.WRITEFUNCTION, self.header_callback)
conn.perform()
rp=Response()
rp.parseResponse(self.__performHead)
self.response=rp
示例14: init_pycurl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def init_pycurl(debug=False):
"""
Provides an instances of pycurl with basic configuration
:return: pycurl instance
"""
_curl = pycurl.Curl()
_curl.setopt(pycurl.SSL_OPTIONS, pycurl.SSLVERSION_TLSv1_2)
_curl.setopt(pycurl.SSL_VERIFYPEER, False)
_curl.setopt(pycurl.SSL_VERIFYHOST, False)
_curl.setopt(pycurl.VERBOSE, debug)
_curl.setopt(pycurl.TIMEOUT, 10)
_curl.setopt(pycurl.COOKIEFILE, "")
_curl.setopt(pycurl.USERAGENT, 'APIFuzzer')
return _curl
示例15: get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import SSL_VERIFYHOST [as 别名]
def get(self,
url,
header=None,
proxy_host=None,
proxy_port=None,
cookie_file=None):
'''
open url width get method
@param url: the url to visit
@param header: the http header
@param proxy_host: the proxy host name
@param proxy_port: the proxy port
'''
crl = pycurl.Curl()
#crl.setopt(pycurl.VERBOSE,1)
crl.setopt(pycurl.NOSIGNAL, 1)
# set proxy
# crl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
rel_proxy_host = proxy_host or self.proxy_host
if rel_proxy_host:
crl.setopt(pycurl.PROXY, rel_proxy_host)
rel_proxy_port = proxy_port or self.proxy_port
if rel_proxy_port:
crl.setopt(pycurl.PROXYPORT, rel_proxy_port)
# set cookie
rel_cookie_file = cookie_file or self.cookie_file
if rel_cookie_file:
crl.setopt(pycurl.COOKIEFILE, rel_cookie_file)
crl.setopt(pycurl.COOKIEJAR, rel_cookie_file)
# set ssl
crl.setopt(pycurl.SSL_VERIFYPEER, 0)
crl.setopt(pycurl.SSL_VERIFYHOST, 0)
crl.setopt(pycurl.SSLVERSION, 3)
crl.setopt(pycurl.CONNECTTIMEOUT, 10)
crl.setopt(pycurl.TIMEOUT, 300)
crl.setopt(pycurl.HTTPPROXYTUNNEL, 1)
rel_header = header or self.header
if rel_header:
crl.setopt(pycurl.HTTPHEADER, rel_header)
crl.fp = StringIO.StringIO()
if isinstance(url, unicode):
url = str(url)
crl.setopt(pycurl.URL, url)
crl.setopt(crl.WRITEFUNCTION, crl.fp.write)
try:
crl.perform()
except Exception, e:
raise CurlException(e)