Do a HTTP request, with retry if we get disconnected (e.g. due to a timeout). This is a workaround for https://bugs.python.org/issue3566 which is fixed in Python 3.5.
(self, method, path, postdata)
| 113 | return AuthServiceProxy(self.__service_url, name, connection=self.__conn) |
| 114 | |
| 115 | def _request(self, method, path, postdata): |
| 116 | ''' |
| 117 | Do a HTTP request, with retry if we get disconnected (e.g. due to a timeout). |
| 118 | This is a workaround for https://bugs.python.org/issue3566 which is fixed in Python 3.5. |
| 119 | ''' |
| 120 | headers = {'Host': self.__url.hostname, |
| 121 | 'User-Agent': USER_AGENT, |
| 122 | 'Authorization': self.__auth_header, |
| 123 | 'Content-type': 'application/json'} |
| 124 | try: |
| 125 | self.__conn.request(method, path, postdata, headers) |
| 126 | return self._get_response() |
| 127 | except httplib.BadStatusLine as e: |
| 128 | if e.line == "''": # if connection was closed, try again |
| 129 | self.__conn.close() |
| 130 | self.__conn.request(method, path, postdata, headers) |
| 131 | return self._get_response() |
| 132 | else: |
| 133 | raise |
| 134 | except (BrokenPipeError,ConnectionResetError): |
| 135 | # Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset |
| 136 | # ConnectionResetError happens on FreeBSD with Python 3.4 |
| 137 | self.__conn.close() |
| 138 | self.__conn.request(method, path, postdata, headers) |
| 139 | return self._get_response() |
| 140 | |
| 141 | def __call__(self, *args, **argsn): |
| 142 | AuthServiceProxy.__id_count += 1 |
no test coverage detected