本文整理匯總了Python中pycurl.SSL_VERIFYPEER屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.SSL_VERIFYPEER屬性的具體用法?Python pycurl.SSL_VERIFYPEER怎麽用?Python pycurl.SSL_VERIFYPEER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pycurl
的用法示例。
在下文中一共展示了pycurl.SSL_VERIFYPEER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pycurl_insecure
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [as 別名]
def test_pycurl_insecure(self):
curl = CurlStub(b"result")
result = fetch("http://example.com/get-ca-cert", curl=curl,
insecure=True)
self.assertEqual(result, b"result")
self.assertEqual(curl.options,
{pycurl.URL: b"http://example.com/get-ca-cert",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 30,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 600,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.SSL_VERIFYPEER: False,
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例2: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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)]
示例3: __init__
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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: _set_common
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [as 別名]
def _set_common(self, c):
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.AUTOREFERER, 1)
c.setopt(pycurl.ENCODING, self._accept_encoding)
c.setopt(pycurl.MAXREDIRS, 255)
c.setopt(pycurl.CONNECTTIMEOUT, 30)
c.setopt(pycurl.TIMEOUT, 300)
c.setopt(pycurl.NOSIGNAL, 1)
if self._proxy:
c.setopt(pycurl.PROXY, self._proxy)
if self._url.scheme == 'https':
c.setopt(pycurl.SSLVERSION, 3)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
示例5: connect
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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)
示例6: head
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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
示例7: secure_download
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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
示例8: test_secure_download
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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")
示例9: test_secure_download_no_cainfo
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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")
示例10: getPage
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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 = ''
示例11: __init__
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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)
示例12: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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()
示例13: head
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import SSL_VERIFYPEER [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_VERIFYPEER [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_VERIFYPEER [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)