def request(self): stderr_proxy = StderrProxy() try: with stderr_proxy.record(): self.curl.perform() except pycurl.error as ex: # CURLE_WRITE_ERROR (23) # An error occurred when writing received data to a local file, or # an error was returned to libcurl from a write callback. # This exception should be ignored if grab_callback_interrupted flag # is enabled (this happens when nohead or nobody options enabled) # # Also this error is raised when curl receives KeyboardInterrupt # while it is processing some callback function # (WRITEFUNCTION, HEADERFUNCTIO, etc) # If you think WTF then see details here: # https://github.com/pycurl/pycurl/issues/413 if self.has_pycurl_hidden_sigint(stderr_proxy.get_output()): raise KeyboardInterrupt if 23 == ex.args[0]: if getattr(self.curl, 'grab_callback_interrupted', None) is True: # This is expected error caused by # interruptted execution of body_processor callback # FIXME: is it set automatically? self.curl.grab_callback_interrupted = False else: raise error.GrabNetworkError(ex.args[0], ex.args[1]) else: if ex.args[0] == 28: raise error.GrabTimeoutError(ex.args[0], ex.args[1]) elif ex.args[0] == 7: raise error.GrabConnectionError(ex.args[0], ex.args[1]) elif ex.args[0] == 67: raise error.GrabAuthError(ex.args[0], ex.args[1]) elif ex.args[0] == 47: raise error.GrabTooManyRedirectsError(ex.args[0], ex.args[1]) elif ex.args[0] == 6: raise error.GrabCouldNotResolveHostError(ex.args[0], ex.args[1]) else: raise error.GrabNetworkError(ex.args[0], ex.args[1]) except Exception as ex: # pylint: disable=broad-except if self.has_pycurl_hidden_sigint(stderr_proxy.get_output()): raise KeyboardInterrupt six.reraise(error.GrabInternalError, error.GrabInternalError(ex), sys.exc_info()[2]) else: if self.has_pycurl_hidden_sigint(stderr_proxy.get_output()): raise KeyboardInterrupt
def request(self): sigint_handler = PycurlSigintHandler() try: with sigint_handler.handle_sigint(): self.curl.perform() except pycurl.error as ex: new_ex = build_grab_exception(ex, self.curl) if new_ex: raise new_ex # pylint: disable=raising-bad-type except Exception as ex: # pylint: disable=broad-except six.reraise(error.GrabInternalError, error.GrabInternalError(ex), sys.exc_info()[2]) finally: self.curl.grab_callback_interrupted = False
def request(self): try: self.curl.perform() except pycurl.error as ex: # CURLE_WRITE_ERROR (23) # An error occurred when writing received data to a local file, or # an error was returned to libcurl from a write callback. # This exception should be ignored if _callback_interrupted flag # is enabled (this happens when nohead or nobody options enabled) # # Also this error is raised when curl receives KeyboardInterrupt # while it is processing some callback function # (WRITEFUNCTION, HEADERFUNCTIO, etc) if 23 == ex.args[0]: if getattr(self.curl, '_callback_interrupted', None) is True: self.curl._callback_interrupted = False else: raise error.GrabNetworkError(ex.args[0], ex.args[1]) else: if ex.args[0] == 28: raise error.GrabTimeoutError(ex.args[0], ex.args[1]) elif ex.args[0] == 7: raise error.GrabConnectionError(ex.args[0], ex.args[1]) elif ex.args[0] == 67: raise error.GrabAuthError(ex.args[0], ex.args[1]) elif ex.args[0] == 47: raise error.GrabTooManyRedirectsError( ex.args[0], ex.args[1]) elif ex.args[0] == 6: raise error.GrabCouldNotResolveHostError( ex.args[0], ex.args[1]) else: raise error.GrabNetworkError(ex.args[0], ex.args[1]) except Exception as ex: six.reraise(error.GrabInternalError, error.GrabInternalError(ex), sys.exc_info()[2])