Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/authproxy.py
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | def _request(self, method, path, postdata): | ||||
headers = {'Host': self.__url.hostname, | headers = {'Host': self.__url.hostname, | ||||
'User-Agent': USER_AGENT, | 'User-Agent': USER_AGENT, | ||||
'Authorization': self.__auth_header, | 'Authorization': self.__auth_header, | ||||
'Content-type': 'application/json'} | 'Content-type': 'application/json'} | ||||
if os.name == 'nt': | if os.name == 'nt': | ||||
# Windows somehow does not like to re-use connections | # Windows somehow does not like to re-use connections | ||||
# TODO: Find out why the connection would disconnect occasionally | # TODO: Find out why the connection would disconnect occasionally | ||||
# and make it reusable on Windows | # and make it reusable on Windows | ||||
# Avoid "ConnectionAbortedError: [WinError 10053] An established | |||||
# connection was aborted by the software in your host machine" | |||||
self._set_conn() | self._set_conn() | ||||
try: | try: | ||||
self.__conn.request(method, path, postdata, headers) | self.__conn.request(method, path, postdata, headers) | ||||
return self._get_response() | return self._get_response() | ||||
except http.client.BadStatusLine as e: | except (BrokenPipeError, ConnectionResetError): | ||||
if e.line == "''": # if connection was closed, try again | # Python 3.5+ raises BrokenPipeError when the connection was reset | ||||
# ConnectionResetError happens on FreeBSD | |||||
self.__conn.close() | self.__conn.close() | ||||
self.__conn.request(method, path, postdata, headers) | self.__conn.request(method, path, postdata, headers) | ||||
return self._get_response() | return self._get_response() | ||||
else: | except OSError as e: | ||||
raise | retry = ( | ||||
except (BrokenPipeError, ConnectionResetError): | '[WinError 10053] An established connection was aborted by the software in your host machine' in str(e)) | ||||
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset | if retry: | ||||
# ConnectionResetError happens on FreeBSD with Python 3.4 | |||||
self.__conn.close() | self.__conn.close() | ||||
self.__conn.request(method, path, postdata, headers) | self.__conn.request(method, path, postdata, headers) | ||||
return self._get_response() | return self._get_response() | ||||
else: | |||||
raise | |||||
def get_request(self, *args, **argsn): | def get_request(self, *args, **argsn): | ||||
AuthServiceProxy.__id_count += 1 | AuthServiceProxy.__id_count += 1 | ||||
log.debug("-{}-> {} {}".format( | log.debug("-{}-> {} {}".format( | ||||
AuthServiceProxy.__id_count, self._service_name, json.dumps( | AuthServiceProxy.__id_count, self._service_name, json.dumps( | ||||
args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii))) | args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii))) | ||||
if args and argsn: | if args and argsn: | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |