def _run(self): # Authenticate url = "%s://%s%s" % (self.scheme, self.host, self.url) # Connect and process the stream error_counter = 0 conn = None exception = None logger.debug(u"run streaming server.") while self.running: # quit if error count greater than retry count if self.retry_count is not None and error_counter > self.retry_count: break try: if self.scheme == "http": conn = httplib.HTTPConnection(self.host) else: conn = httplib.HTTPSConnection(self.host) self.auth.apply_auth(url, 'POST', self.headers, self.parameters) conn.connect() conn.sock.settimeout(self.timeout) conn.request('POST', self.url, self.body, headers=self.headers) logger.debug(u"wait response.") resp = conn.getresponse() logger.debug(u"connect response: %s" % str(resp)) if resp.status != 200: if self.listener.on_error(resp.status) is False: break error_counter += 1 logger.error("response status: error(%s)", (str(resp.status), )) sleep(self.retry_time) else: error_counter = 0 logger.info("response status: ok(%s)", (str(resp.status), )) self._read_loop(resp) except socket.error, err: self.listener.on_socket_error(err) except socket.gaierror, err: self.listener.on_socket_error(err)
def _run(self): # Authenticate url = "%s://%s%s" % (self.scheme, self.host, self.url) # Connect and process the stream error_counter = 0 conn = None exception = None logger.debug(u"run streaming server.") while self.running: # quit if error count greater than retry count if self.retry_count is not None and error_counter > self.retry_count: break try: if self.scheme == "http": conn = httplib.HTTPConnection(self.host) else: conn = httplib.HTTPSConnection(self.host) self.auth.apply_auth(url, 'POST', self.headers, self.parameters) conn.connect() conn.sock.settimeout(self.timeout) conn.request('POST', self.url, self.body, headers=self.headers) logger.debug(u"wait response.") resp = conn.getresponse() logger.debug(u"connect response: %s" % str(resp)) if resp.status != 200: if self.listener.on_error(resp.status) is False: break error_counter += 1 logger.error("response status: error(%s)", (str(resp.status),)) sleep(self.retry_time) else: error_counter = 0 logger.info("response status: ok(%s)", (str(resp.status),)) self._read_loop(resp) except socket.error, err: self.listener.on_socket_error(err) except socket.gaierror, err: self.listener.on_socket_error(err)
self.listener.on_socket_error(err) except socket.gaierror, err: self.listener.on_socket_error(err) except NoResponse, err: self.listener.on_noresponse(err) except timeout: logger.info("response status: timeout") if self.listener.on_timeout() == False: break if self.running is False: break conn.close() sleep(self.snooze_time) except Exception, exception: if self.listener.on_fatal_error(exception): continue raise # any other exception is fatal, so kill loop #break logger.error("(%s):%s" % ("_run", "false")) # cleanup self.running = False if conn: conn.close()