예제 #1
0
    def get(self, url, params=None):
        url = self.restApiUrl + url
        if params is not None:
            url += '?' + '&'.join(
                '{}={}'.format(
                    k,
                    six.moves.urllib.parse.quote(
                        six.text_type(v).encode('utf8')))
                for k, v in params.iteritems())  # @UndefinedVariable

        logger.debug('Requesting {}'.format(url))

        try:
            r = requests.get(url,
                             headers={
                                 'Content-type':
                                 'application/json',
                                 'User-Agent':
                                 osDetector.getOs() + " - UDS Connector " +
                                 VERSION
                             },
                             verify=False)
        except requests.exceptions.ConnectionError as e:
            raise Exception('Error connecting to UDS Server at {}'.format(
                self.restApiUrl[0:-11]))

        if r.ok:
            logger.debug('Request was OK. {}'.format(r.text))
            data = json.loads(r.text)
            if not 'error' in data:
                return data['result']
            # Has error
            if data.get('retryable', '0') == '1':
                raise RetryException(data['error'])

            raise Exception(data['error'])
        else:
            logger.error('Error requesting {}: {}, {}'.format(
                url, r.code.r.text))
            raise Exception('Error {}: {}'.format(r.code, r.text))

        return data
예제 #2
0
파일: rest.py 프로젝트: dkmstr/openuds
 def get(self):
     request = QNetworkRequest(self.url)
     request.setRawHeader('User-Agent', osDetector.getOs() + " - UDS Connector " + VERSION)
     self._manager.get(request)
예제 #3
0
파일: rest.py 프로젝트: dkmstr/openuds
    def get(self, url, params=None):
        url = self.restApiUrl + url
        if params is not None:
            url += '?' + '&'.join('{}={}'.format(k, six.moves.urllib.parse.quote(six.text_type(v).encode('utf8'))) for k, v in params.iteritems())  # @UndefinedVariable

        logger.debug('Requesting {}'.format(url))

        try:
            r = requests.get(url, headers={'Content-type': 'application/json', 'User-Agent': osDetector.getOs() + " - UDS Connector " + VERSION }, verify=False)
        except requests.exceptions.ConnectionError as e:
            raise Exception('Error connecting to UDS Server at {}'.format(self.restApiUrl[0:-11]))

        if r.ok:
            logger.debug('Request was OK. {}'.format(r.text))
            data = json.loads(r.text)
            if not 'error' in data:
                return data['result']
            # Has error
            if data.get('retryable', '0') == '1':
                raise RetryException(data['error'])

            raise Exception(data['error'])
        else:
            logger.error('Error requesting {}: {}, {}'.format(url, r.code. r.text))
            raise Exception('Error {}: {}'.format(r.code, r.text))

        return data
예제 #4
0
 def get(self):
     request = QNetworkRequest(self.url)
     request.setRawHeader(
         'User-Agent',
         osDetector.getOs() + " - UDS Connector " + VERSION)
     self._manager.get(request)