diff --git a/prexview.py b/prexview.py index 9ff5f61..3a6bdfd 100644 --- a/prexview.py +++ b/prexview.py @@ -28,8 +28,8 @@ def __send(self, data): response = post(self._URL + 'transform', data = data, headers = headers) - if response.raise_for_status() is not None: - return None + if response.status_code != 200: + raise Exception(loads(response.content)['error']) result = { 'rateLimit': response.headers['x-ratelimit-limit'], @@ -37,7 +37,7 @@ def __send(self, data): 'rateRemaining': response.headers['x-ratelimit-remaining'], } - if response.status_code is 200: + if response.status_code == 200: result['id'] = response.headers['x-transaction-id'] result['file'] = response.content result['responseTime'] = response.headers['x-response-time'] @@ -47,14 +47,14 @@ def __send(self, data): def __isJson(self, str): try: json = loads(str) - except ValueError, e: + except ValueError as e: return False return True def __checkOptions(self, _format, options): # JSON - if _format is 'json': + if _format == 'json': if type(options['json']) is str: if self.__isJson(options['json']) is not True: raise Exception('PrexView content must be a valid JSON string') @@ -104,7 +104,7 @@ def __checkOptions(self, _format, options): return options def __checkToken(self): - if self.token is None or self.token is '': + if self.token is None or self.token == '': raise Exception('PrexView environment variable PXV_API_KEY must be set') def sendXML(self, content, options): diff --git a/tests/test_json.py b/tests/test_json.py index bf25459..5e9c2ac 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -1,7 +1,7 @@ # coding: utf-8 -from prexview import Prexview +from prexview import PrexView -pxv = Prexview() +pxv = PrexView() options = {'design': 'custom-invoice', 'output': 'pdf'} json = { @@ -21,6 +21,6 @@ f.write(res['file']) f.close() - print 'File created:', file + print('File created:', file) except Exception as e: - print e + print(e) diff --git a/tests/test_xml.py b/tests/test_xml.py index d3e000e..096f87c 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -1,7 +1,7 @@ # coding: utf-8 -from prexview import Prexview +from prexview import PrexView -pxv = Prexview() +pxv = PrexView() options = dict(design='custom-invoice', output='pdf') xml = ''' @@ -20,6 +20,6 @@ f.write(res['file']) f.close() - print 'File created:', file + print('File created:', file) except Exception as e: - print e + print(e)