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)
| 94 | return AuthServiceProxy(self.__service_url, name, connection=self.__conn) |
| 95 | |
| 96 | def _request(self, method, path, postdata): |
| 97 | ''' |
| 98 | Do a HTTP request, with retry if we get disconnected (e.g. due to a timeout). |
| 99 | This is a workaround for https://bugs.python.org/issue3566 which is fixed in Python 3.5. |
| 100 | ''' |
| 101 | headers = {'Host': self.__url.hostname, |
| 102 | 'User-Agent': USER_AGENT, |
| 103 | 'Authorization': self.__auth_header, |
| 104 | 'Content-type': 'application/json'} |
| 105 | try: |
| 106 | self.__conn.request(method, path, postdata, headers) |
| 107 | return self._get_response() |
| 108 | except http.client.BadStatusLine as e: |
| 109 | if e.line == "''": # if connection was closed, try again |
| 110 | self.__conn.close() |
| 111 | self.__conn.request(method, path, postdata, headers) |
| 112 | return self._get_response() |
| 113 | else: |
| 114 | raise |
| 115 | except (BrokenPipeError, ConnectionResetError): |
| 116 | # Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset |
| 117 | # ConnectionResetError happens on FreeBSD with Python 3.4 |
| 118 | self.__conn.close() |
| 119 | self.__conn.request(method, path, postdata, headers) |
| 120 | return self._get_response() |
| 121 | |
| 122 | def get_request(self, *args, **argsn): |
| 123 | AuthServiceProxy.__id_count += 1 |
no test coverage detected