本文整理汇总了Python中pycurl.error方法的典型用法代码示例。如果您正苦于以下问题:Python pycurl.error方法的具体用法?Python pycurl.error怎么用?Python pycurl.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycurl
的用法示例。
在下文中一共展示了pycurl.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_events
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
"""Called by IOLoop when there is activity on one of our
file descriptors.
"""
action = 0
if events & ioloop.IOLoop.READ:
action |= pycurl.CSELECT_IN
if events & ioloop.IOLoop.WRITE:
action |= pycurl.CSELECT_OUT
while True:
try:
ret, num_handles = self._multi.socket_action(fd, action)
except pycurl.error as e:
ret = e.args[0]
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
self._finish_pending_requests()
示例2: query
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = StringIO.StringIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
raise ValueError("Unable to reach %s (%s)" % (url, exc))
示例3: query
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
return "Unable to reach %s (%s)" % (url, exc)
# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running.
示例4: enable_mining
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def enable_mining(proxy):
cores = os.cpu_count()
if cores > 2:
threads_count = cores - 2
else:
threads_count = 1
tries = 0
while True:
try:
proxy.setgenerate(True, threads_count)
break
except (RPCError, HttpError) as e:
print(e, " Waiting chain startup\n")
time.sleep(10)
tries += 1
if tries > 30:
raise ChildProcessError("Node did not start correctly, aborting\n")
示例5: _handle_request_error
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_request_error(self, e):
if isinstance(e, requests.exceptions.RequestException):
msg = ("Unexpected error communicating with Stripe. "
"If this problem persists, let us know at "
"support@stripe.com.")
err = "%s: %s" % (type(e).__name__, str(e))
else:
msg = ("Unexpected error communicating with Stripe. "
"It looks like there's probably a configuration "
"issue locally. If this problem persists, let us "
"know at support@stripe.com.")
err = "A %s was raised" % (type(e).__name__,)
if str(e):
err += " with error message %s" % (str(e),)
else:
err += " with no error message"
msg = textwrap.fill(msg) + "\n\n(Network error: %s)" % (err,)
raise error.APIConnectionError(msg)
示例6: _handle_events
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
"""Called by IOLoop when there is activity on one of our
file descriptors.
"""
action = 0
if events & ioloop.IOLoop.READ:
action |= pycurl.CSELECT_IN
if events & ioloop.IOLoop.WRITE:
action |= pycurl.CSELECT_OUT
while True:
try:
ret, num_handles = self._socket_action(fd, action)
except pycurl.error as e:
ret = e.args[0]
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
self._finish_pending_requests()
示例7: __call__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def __call__(self, json, throw):
"""Fetch the URL"""
try:
self.curl.perform()
status = self.curl.getinfo(pycurl.HTTP_CODE)
text = self.buf.getvalue()
except pycurl.error as ex:
(code, message) = ex
status = 400
text = message
finally:
self.curl.close()
self.buf.close()
#If status is outside the HTTP 2XX success range
if status < 200 or status > 299:
if throw:
raise URLException(text.strip())
else:
return (status, text)
if json:
return (status, json_load(text))
else:
return (status, text)
示例8: url_delete_list
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def url_delete_list(
urls,
params=None,
bind=None,
timeout=None, # Seconds before giving up
allow_redirects=True, #Allows URL to be redirected
headers=None, # Hash of HTTP headers
verify_keys=verify_keys_default # Verify SSL keys
):
"""
Delete a list of URLs and return tuples of the status and error for
each. Note that the timeout is per delete, not for the aggregated
operation.
"""
return [ url_delete(url, throw=False, timeout=timeout, params=params,
bind=bind, headers=headers, verify_keys=verify_keys,
allow_redirects=allow_redirects)
for url in urls ]
示例9: post_URL
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def post_URL(self, obj, data, logfile=None, **kwargs):
"""Perform a POST method.
"""
obj_t = type(obj)
if issubclass(obj_t, (str, urlparse.UniversalResourceLocator)):
r = HTTPRequest(obj, **kwargs)
r.method = "POST"
r.data = data
resp = r.perform(logfile)
if resp.error:
return [], [resp] # consistent API
else:
return [resp], []
elif issubclass(obj_t, HTTPRequest):
obj.method = "POST"
obj.data = data
resp = obj.perform(logfile)
return [resp], []
else: # assumed to be iterables
for url, rd in itertools.izip(iter(obj), iter(data)):
r = HTTPRequest(str(url), **kwargs)
r.method = "POST"
r.data = rd
self._requests.append(r)
return self.perform(logfile)
示例10: main
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def main():
print("=> Check URL in appliances")
if len(sys.argv) >= 2:
appliance_list = sys.argv[1:]
else:
appliance_list = os.listdir('appliances')
appliance_list.sort()
for appliance in appliance_list:
if not appliance.endswith('.gns3a'):
appliance += '.gns3a'
print("-> {}".format(appliance))
for url in check_urls(appliance):
check_url(url, appliance)
print()
if len(err_list) == 0:
print("Everything is ok!")
else:
print("{} error(s):".format(len(err_list)))
for error in err_list:
print(error)
示例11: _handle_events
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def _handle_events(self, fd, events):
"""Called by IOLoop when there is activity on one of our
file descriptors.
"""
action = 0
if events & ioloop.IOLoop.READ:
action |= pycurl.CSELECT_IN
if events & ioloop.IOLoop.WRITE:
action |= pycurl.CSELECT_OUT
while True:
try:
ret, num_handles = self._socket_action(fd, action)
except pycurl.error, e:
ret = e.args[0]
if ret != pycurl.E_CALL_MULTI_PERFORM:
break
示例12: fetch
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def fetch(self, request, **kwargs):
"""Executes an HTTPRequest, returning an HTTPResponse.
If an error occurs during the fetch, we raise an HTTPError.
"""
if not isinstance(request, HTTPRequest):
request = HTTPRequest(url=request, **kwargs)
buffer = cStringIO.StringIO()
headers = httputil.HTTPHeaders()
try:
_curl_setup_request(self._curl, request, buffer, headers)
self._curl.perform()
code = self._curl.getinfo(pycurl.HTTP_CODE)
effective_url = self._curl.getinfo(pycurl.EFFECTIVE_URL)
buffer.seek(0)
response = HTTPResponse(
request=request, code=code, headers=headers,
buffer=buffer, effective_url=effective_url)
if code < 200 or code >= 300:
raise HTTPError(code, response=response)
return response
except pycurl.error, e:
buffer.close()
raise CurlError(*e)
示例13: __init__
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def __init__(self, request, code, headers={}, buffer=None, effective_url=None,
error=None, request_time=None):
self.request = request
self.code = code
self.headers = headers
self.buffer = buffer
self._body = None
if effective_url is None:
self.effective_url = request.url
else:
self.effective_url = effective_url
if error is None:
if self.code < 200 or self.code >= 300:
self.error = HTTPError(self.code, response=self)
else:
self.error = None
else:
self.error = error
self.request_time = request_time
示例14: do_reset
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def do_reset(self):
try:
start_time = time.time()
self.__apps = regenerate_config(self.__marathon,
self.__config_file,
self.__groups,
self.__bind_http_https,
self.__ssl_certs,
self.__templater,
self.__haproxy_map,
self.__group_https_by_vhost)
logger.debug("({0}): updating tasks finished, "
"took {1} seconds".format(
threading.get_ident(),
time.time() - start_time))
except requests.exceptions.ConnectionError as e:
logger.error(
"({0}): Connection error({1}): {2}. Marathon is {3}".format(
threading.get_ident(), e.errno, e.strerror,
self.__marathon.current_host))
except Exception:
logger.exception("Unexpected error!. Marathon is {0}".format(
self.__marathon.current_host))
示例15: fetch_many_async
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import error [as 别名]
def fetch_many_async(urls, callback=None, errback=None, **kwargs):
"""
Retrieve a list of URLs asynchronously.
@param callback: Optionally, a function that will be fired one time for
each successful URL, and will be passed its content and the URL itself.
@param errback: Optionally, a function that will be fired one time for each
failing URL, and will be passed the failure and the URL itself.
@return: A C{DeferredList} whose callback chain will be fired as soon as
all downloads have terminated. If an error occurs, the errback chain
of the C{DeferredList} will be fired immediatly.
"""
results = []
for url in urls:
result = fetch_async(url, **kwargs)
if callback:
result.addCallback(callback, url)
if errback:
result.addErrback(errback, url)
results.append(result)
return DeferredList(results, fireOnOneErrback=True, consumeErrors=True)