def execute(self, request):
url = request.uri<EOL>if request.parameters:<EOL><INDENT>url += '<STR_LIT:?>' + urlencode(request.parameters)<EOL><DEDENT>if request.headers:<EOL><INDENT>headers = dict(self._headers, **request.headers)<EOL><DEDENT>else:<EOL><INDENT>headers = self._headers<EOL><DEDENT>retry = <NUM_LIT:0><EOL>server = getattr(self._local, "<STR_LIT>", None)<EOL>while True:<EOL><INDENT>if not server:<EOL><INDENT>self._local.server = server = self._get_server()<EOL><DEDENT>try:<EOL><INDENT>parse_result = urlparse(server)<EOL>conn = get_pool().connection_from_host(parse_result.hostname,<EOL>parse_result.port,<EOL>parse_result.scheme)<EOL>kwargs = dict(<EOL>method=Method._VALUES_TO_NAMES[request.method],<EOL>url=parse_result.path + url,<EOL>body=request.body,<EOL>headers=headers,<EOL>timeout=self._timeout,<EOL>)<EOL>response = conn.urlopen(**kwargs)<EOL>return RestResponse(status=response.status,<EOL>body=response.data,<EOL>headers=response.headers)<EOL><DEDENT>except (IOError, urllib3.exceptions.HTTPError) as ex:<EOL><INDENT>self._drop_server(server)<EOL>self._local.server = server = None<EOL>if retry >= self._max_retries:<EOL><INDENT>logger.error("<STR_LIT>",<EOL>self._max_retries, exc_info=<NUM_LIT:1>)<EOL>raise NoServerAvailable(ex)<EOL><DEDENT>logger.exception("<STR_LIT>", self._max_retries - retry)<EOL>retry += <NUM_LIT:1><EOL><DEDENT><DEDENT>
Execute a request and return a response