本文整理匯總了Python中pycurl.TIMEOUT屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.TIMEOUT屬性的具體用法?Python pycurl.TIMEOUT怎麽用?Python pycurl.TIMEOUT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pycurl
的用法示例。
在下文中一共展示了pycurl.TIMEOUT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def send_REST_request(ip, port, object, match_key,
match_value, detail):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/%s" % (ip, port, object)
args_str = ''
if match_key:
args_str += match_key + "=" + match_value
if detail:
args_str += "&detail"
if args_str != '':
url += "?" + args_str
conn = pycurl.Curl()
conn.setopt(pycurl.TIMEOUT, 1)
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.HTTPGET, 1)
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
# end def send_REST_request
示例2: generate_curl
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def generate_curl(self, url=None, headers=None):
""" 生成一個curl, 返回 curl 實例和用於獲取結果的 buffer
"""
curl = pycurl.Curl()
buff = StringIO()
curl.setopt(pycurl.COOKIEFILE, "cookie")
curl.setopt(pycurl.COOKIEJAR, "cookie_jar")
curl.setopt(pycurl.SHARE, self.http._share)
curl.setopt(pycurl.WRITEFUNCTION, buff.write)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.TIMEOUT, 3)
curl.setopt(pycurl.CONNECTTIMEOUT, 3)
if url:
curl.setopt(pycurl.URL, url)
if headers:
self.set_curl_headers(curl, headers)
return curl, buff
示例3: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [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)
示例4: __init__
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def __init__(self, url):
self.curl = pycurl.Curl()
self.curl.setopt(pycurl.FOLLOWLOCATION, 1)
self.curl.setopt(pycurl.MAXREDIRS, 5)
self.curl.setopt(pycurl.CONNECTTIMEOUT, 30)
self.curl.setopt(pycurl.TIMEOUT, 300)
self.curl.setopt(pycurl.NOSIGNAL, 1)
self.curl.setopt(pycurl.WRITEFUNCTION, self.write_cb)
self.curl.setopt(pycurl.URL, url)
self.curl.connection = self
# 合計下載字節數
self.total_downloaded = 0
示例5: url_check
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def url_check(self, url):
'''下載地址檢查'''
url_info = {}
proto = urlparse.urlparse(url)[0]
if proto not in VALIDPROTOCOL:
print 'Valid protocol should be http or ftp, but % s found < %s >!' % (proto, url)
else:
ss = StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 300)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.NOPROGRESS, 1)
curl.setopt(pycurl.NOBODY, 1)
curl.setopt(pycurl.HEADERFUNCTION, ss.write)
curl.setopt(pycurl.URL, url)
try:
curl.perform()
except:
pass
if curl.errstr() == '' and curl.getinfo(pycurl.RESPONSE_CODE) in STATUS_OK:
url_info['url'] = curl.getinfo(pycurl.EFFECTIVE_URL)
url_info['file'] = os.path.split(url_info['url'])[1]
url_info['size'] = int(
curl.getinfo(pycurl.CONTENT_LENGTH_DOWNLOAD))
url_info['partible'] = (ss.getvalue().find('Accept - Ranges') != -1)
return url_info
示例6: _set_common
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [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)
示例7: get
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def get(url, encoding, user_agent=UA, referrer=None):
"""Make a GET request of the url using pycurl and return the data
(which is None if unsuccessful)"""
data = None
databuffer = BytesIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 5)
curl.setopt(pycurl.TIMEOUT, 8)
curl.setopt(pycurl.WRITEDATA, databuffer)
curl.setopt(pycurl.COOKIEFILE, '')
if user_agent:
curl.setopt(pycurl.USERAGENT, user_agent)
if referrer is not None:
curl.setopt(pycurl.REFERER, referrer)
try:
curl.perform()
data = databuffer.getvalue().decode(encoding)
except Exception:
pass
curl.close()
return data
示例8: _set_extra_options
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def _set_extra_options(self, c, fuzzres, poolid):
if self.pool_map[poolid]["proxy"]:
ip, port, ptype = next(self.pool_map[poolid]["proxy"])
fuzzres.history.wf_proxy = (("%s:%s" % (ip, port)), ptype)
if ptype == "SOCKS5":
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
elif ptype == "SOCKS4":
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4)
elif ptype == "HTTP":
c.setopt(pycurl.PROXY, "%s:%s" % (ip, port))
else:
raise FuzzExceptBadOptions("Bad proxy type specified, correct values are HTTP, SOCKS4 or SOCKS5.")
else:
c.setopt(pycurl.PROXY, "")
mdelay = self.options.get("req_delay")
if mdelay is not None:
c.setopt(pycurl.TIMEOUT, mdelay)
cdelay = self.options.get("conn_delay")
if cdelay is not None:
c.setopt(pycurl.CONNECTTIMEOUT, cdelay)
return c
示例9: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def send_REST_request(ip, port, action, payload):
try:
url = "http://%s:%s/dhcp_event?action=%s" % (ip, port, action)
headers = ["Content-Type:application/json"]
conn = pycurl.Curl()
conn.setopt(pycurl.TIMEOUT, 1)
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.POST, 1)
conn.setopt(pycurl.POSTFIELDS, payload)
conn.perform()
except:
return
示例10: test_get_html_http_no_callbacks
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def test_get_html_http_no_callbacks(self):
import pycurl
import io
# Test http with no callbacks
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.WRITEFUNCTION, mock_stringio_instance.write),
call(pycurl.FOLLOWLOCATION, 1),
call(pycurl.MAXREDIRS, 10),
call(
pycurl.USERAGENT,
"Fedora Upstream Release Monitoring "
"(https://fedoraproject.org/wiki/Upstream_release_monitoring)",
),
call(pycurl.CONNECTTIMEOUT, 10),
call(pycurl.TIMEOUT, 30),
]
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
get_html_result = helpers.get_html("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()
self.assertEqual(get_html_result, "mock StringIO value")
示例11: download_url
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def download_url(host_id, url):
"""
Downloads an URL and stores the response to a directory with named as the host/IP
:param host_id:
:param url:
:return:
"""
output = StringIO.StringIO()
header = StringIO.StringIO()
print "[>] Trying to download URL: %s" % url
# Download file
try:
# 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)')
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(pycurl.CONNECTTIMEOUT, 10)
c.setopt(pycurl.TIMEOUT, 180)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)')
c.setopt(c.WRITEFUNCTION, output.write)
c.setopt(c.HEADERFUNCTION, header.write)
c.perform()
# Header parsing
header_info = header_function(header.getvalue())
except Exception, e:
if args.debug:
traceback.print_exc()
print_highlighted("[-] Error MESSAGE: %s" % str(e))
# Write File
示例12: get_url
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def get_url (url, user_agent=UA, referrer=None):
"""Make a GET request of the url using pycurl and return the data
(which is None if unsuccessful)"""
data = None
databuffer = StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 5)
curl.setopt(pycurl.TIMEOUT, 8)
curl.setopt(pycurl.WRITEFUNCTION, databuffer.write)
curl.setopt(pycurl.COOKIEFILE, '')
if user_agent:
curl.setopt(pycurl.USERAGENT, user_agent)
if referrer is not None:
curl.setopt(pycurl.REFERER, referrer)
try:
curl.perform()
data = databuffer.getvalue()
except Exception:
pass
curl.close()
return data
示例13: getPage
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [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 = ''
示例14: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [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()
示例15: set_timeout
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import TIMEOUT [as 別名]
def set_timeout(self, timeout):
"Set timeout for a retrieving an object"
self.set_option(pycurl.TIMEOUT, timeout)