def request(self, method, path=None, payload=None, headers=None, binary=False, strip_binary=False): """Make request to server""" #if sub attachment we get back binary data if re.search('\/attachments\/', path): logging.debug('found attachment') if path.endswith('content'): logging.debug('found attachment CONTENT') binary = True else: logging.debug('found attachment STRIP') strip_binary = True headers = headers or dict() #headers.setdefault('Accept', 'text/plain') #headers.setdefault('Accept', 'application/vnd.ms-excel') #headers.setdefault('Accept', 'application/pdf') #headers={'Content-Type': 'application/pdf'} #header = {'Content-Type': 'application/octet-stream'} if payload: payload = forms.encode(payload, headers) self.logger.debug('{0} {1}'.format(method, path)) self.logger.debug(headers) req = Request( url=self.auth.url + path, data=payload, headers=headers, ) try: response = self.auth.open(req) except HTTPError as e: response = e if binary: return response elif strip_binary: return response.read().split('Content')[0] else: data = response.read() status = re.split('\n', data, 1)[0] return re.split('\n', data, 1)[1]
def request(self, method, path=None, payload=None, headers=None): """Make request to server""" headers = headers or dict() headers.setdefault('Accept', 'text/plain') if payload: payload = forms.encode(payload, headers) self.logger.debug('{0} {1}'.format(method, path)) self.logger.debug(headers) self.logger.debug('%r' % payload) req = Request( url=self.auth.url + path, data=payload, headers=headers, ) try: response = self.auth.open(req) except HTTPError as e: response = e return self.response_cls(req, response)