diff --git a/HISTORY.rst b/HISTORY.rst index 5b5628a..1f12f19 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,11 @@ History ======== +2.1.4 (2019-06-02) +------------------ + +* Handle BadStatusLine errors + 2.1.3 (2019-06-01) ------------------ diff --git a/simplenote/__init__.py b/simplenote/__init__.py index e35b6f6..30ce9f0 100644 --- a/simplenote/__init__.py +++ b/simplenote/__init__.py @@ -3,5 +3,5 @@ from .simplenote import Simplenote, SimplenoteLoginFailed __author__ = "Daniel Schauenberg" -__version__ = "2.1.3" +__version__ = "2.1.4" __license__ = "MIT" diff --git a/simplenote/simplenote.py b/simplenote/simplenote.py index 1ebb0b7..d74200e 100644 --- a/simplenote/simplenote.py +++ b/simplenote/simplenote.py @@ -15,11 +15,13 @@ from urllib.error import HTTPError import urllib.parse as urllib import html + from http.client import BadStatusLine else: import urllib2 from urllib2 import HTTPError import urllib from HTMLParser import HTMLParser + from httplib import BadStatusLine import base64 import time @@ -81,7 +83,7 @@ def authenticate(self, user, password): try: res = urllib2.urlopen(request).read() token = json.loads(res.decode('utf-8'))["access_token"] - except HTTPError: + except (HTTPError, BadStatusLine): raise SimplenoteLoginFailed('Login to Simplenote API failed!') except IOError: # no connection exception token = None @@ -133,7 +135,7 @@ def get_note(self, noteid, version=None): raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.') else: return e, -1 - except IOError as e: + except (IOError, BadStatusLine) as e: return e, -1 note = json.loads(response.read().decode('utf-8')) note = self.__add_simplenote_api_fields(note, noteid, int(response.info().get("X-Simperium-Version"))) @@ -191,7 +193,7 @@ def update_note(self, note): raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.') else: return e, -1 - except IOError as e: + except (IOError, BadStatusLine) as e: return e, -1 note_to_update = json.loads(response.read().decode('utf-8')) note_to_update = self.__add_simplenote_api_fields(note_to_update, noteid, int(response.info().get("X-Simperium-Version"))) @@ -284,7 +286,7 @@ def get_note_list(self, data=True, since=None, tags=[]): raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.') else: return e, -1 - except IOError as e: + except (IOError, BadStatusLine) as e: return e, -1 # get additional notes if bookmark was set in response @@ -311,7 +313,7 @@ def get_note_list(self, data=True, since=None, tags=[]): raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.') else: return e, -1 - except IOError as e: + except (IOError, BadStatusLine) as e: return e, -1 note_list = notes["index"] self.current = response_notes["current"] @@ -371,7 +373,7 @@ def delete_note(self, note_id): request.add_header(self.header, self.get_token()) try: response = urllib2.urlopen(request) - except IOError as e: + except (IOError, BadStatusLine) as e: return e, -1 except HTTPError as e: if e.code == 401: