Пример #1
0
    def get_requests(self, req_url):
        r = requests.get(url=self.url + req_url, headers=self.headers)
        result = json_loads(r.content)
        if r.status_code != 200:
            return result.get('message')

        return result
Пример #2
0
 def get_access_token(self):
     headers = {
         'Content-Type': 'application/x-www-form-urlencoded',
     }
     data = {
         'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
         'assertion': self.assertion,
     }
     result = requests.post(url=self.req_url, headers=headers, data=data)
     if result.status_code != 200:
         return None
     result = json_loads(result.content)
     return result.get('access_token')
Пример #3
0
    def put_requests(self, req_url, fields):
        multipart = MultipartEncoder(fields)
        data = multipart.to_string()
        self.headers.update({
            'Content-Type': multipart.content_type,
        })
        r = requests.put(url=self.url + req_url,
                         headers=self.headers,
                         data=data)
        result = json_loads(r.content)
        if r.status_code != 200:
            return result.get('message')

        return result
Пример #4
0
    def post_proggress(self, req_url, fields):
        encoder = MultipartEncoder(fields)
        callback = self.create_callback(encoder.len)
        monitor = MultipartEncoderMonitor(encoder, callback)
        self.headers.update({
            'Content-Type': monitor.content_type,
        })
        r = requests.post(url=self.url + req_url,
                          headers=self.headers,
                          data=monitor)
        result = json_loads(r.content)
        if r.status_code != 200:
            return result.get('message')

        return result