def _execute(self, request_url, file_path=None, response_format='py', verbose=False):
        """Execute an API call

           Returns a Python dictionary if response format is 'py' or a string for other formats.
        """

        call_failed = False
        response = str()
        response_content_type = str()
        response_redirect_url = None

        request_url = str(request_url)

        if url_lib.__name__ == 'pycurl':
            curl = url_lib.Curl()

            curl.setopt(curl.URL, request_url)

            if file_path:
                post = [('file', (curl.FORM_FILE, str(file_path)))]
                curl.setopt(curl.HTTPPOST, post)
                if verbose:
                    # Show upload progress
                    curl.setopt(curl.NOPROGRESS, False)
                    curl.setopt(curl.PROGRESSFUNCTION, self._progress)
            else:
                curl.setopt(curl.HTTPGET, True)

            if verbose:
                # Enable verbose output
                curl.setopt(curl.VERBOSE, True)

            # Do not verify that the host name used in the server's certificate
            # matches the API host name
            curl.setopt(curl.SSL_VERIFYHOST, False)

            # Write response to a string
            output = StringIO.StringIO()
            curl.setopt(curl.WRITEFUNCTION, output.write)

            try:
                curl.perform()
                response_content_type = curl.getinfo(curl.CONTENT_TYPE)
                response_redirect_url = curl.getinfo(curl.REDIRECT_URL)
                curl.close()

                response = output.getvalue()
            except Exception, e:
                call_failed = True
                response = curl.errstr()
                if verbose:
                    raise ApiClientException(response)

        elif url_lib.__name__ == 'urllib2':
            if file_path:
                raise NotImplementedError("File upload is not supported when using %s library" \
                                          - url_lib.__name__)
            urllib2 = url_lib
            output = None

            try:
                output = urllib2.urlopen(request_url)
            except urllib2.HTTPError, e:
                # In most cases response with HTTP status code >= 400 is a
                # valid error response from the API server.
                output = e
            except urllib2.URLError, e:
                print str(e)
                call_failed = True
                response = e.reason.args[1]
                if verbose:
                    raise ApiClientException(response)
            except Exception, e:
                call_failed = True
                response = str(e)
                if verbose:
                    raise ApiClientException(response)

            if not call_failed:
                response = output.read()
                response_content_type = output.info().type
                response_redirect_url = output.geturl() \
                                        if (output.geturl() != request_url) \
                                        else None

        if len(response) <= 0:
            if verbose:
                raise ApiClientException("API response is empty")
            else:
                response = {'status': 'error',
                            'code': 'EmptyResponse',
                            'title': 'Empty Response',
                            'message': 'API response is empty'}
        elif response_format == 'py':
            if call_failed:
                response = {'status': 'error',
                            'code': 'CallFailed',
                            'title': 'API Call Failed',
                            'message': response}
            else:
                try:
                    response = pickle.loads(response)
                    if response_redirect_url:
                        response['redirect_url'] = response_redirect_url
                except Exception, e:
                    if verbose:
                        raise ApiClientException(("Failed to parse response", response))
                    else:
                        if (response_content_type.find('application/python') >= 0):
                            # Error while parsing response in pickle format
                            response = {'status': 'error',
                                        'code': 'ParsingError',
                                        'title': 'Parsing Error',
                                        'message': 'An error has occurred while parsing API response'}
                        else:
                            # API server response is not in pickle format
                            response = {'status': 'error',
                                        'code': 'FormatError',
                                        'title': 'Format Error',
                                        'message': 'Unsupported API response format'}

        return response
dataset/ETHPy150Open rmnl/clack/clack/account_client.py/API._execute/operator `%` -> `-`