Skip to content

Commit 74da92f

Browse files
committed
Handle BadStatusLine errors
As far as I can tell this is really an issue in urllib2 as that should really catch and handle this error as URLError or HTTPError. But it doesn't seem to. More details/info in the issue. Fixes: #24
1 parent a2342d6 commit 74da92f

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
History
22
========
33

4+
2.1.4 (2019-06-02)
5+
------------------
6+
7+
* Handle BadStatusLine errors
8+
49
2.1.3 (2019-06-01)
510
------------------
611

simplenote/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
from .simplenote import Simplenote, SimplenoteLoginFailed
44

55
__author__ = "Daniel Schauenberg"
6-
__version__ = "2.1.3"
6+
__version__ = "2.1.4"
77
__license__ = "MIT"

simplenote/simplenote.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
from urllib.error import HTTPError
1616
import urllib.parse as urllib
1717
import html
18+
from http.client import BadStatusLine
1819
else:
1920
import urllib2
2021
from urllib2 import HTTPError
2122
import urllib
2223
from HTMLParser import HTMLParser
24+
from httplib import BadStatusLine
2325

2426
import base64
2527
import time
@@ -81,7 +83,7 @@ def authenticate(self, user, password):
8183
try:
8284
res = urllib2.urlopen(request).read()
8385
token = json.loads(res.decode('utf-8'))["access_token"]
84-
except HTTPError:
86+
except (HTTPError, BadStatusLine):
8587
raise SimplenoteLoginFailed('Login to Simplenote API failed!')
8688
except IOError: # no connection exception
8789
token = None
@@ -133,7 +135,7 @@ def get_note(self, noteid, version=None):
133135
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
134136
else:
135137
return e, -1
136-
except IOError as e:
138+
except (IOError, BadStatusLine) as e:
137139
return e, -1
138140
note = json.loads(response.read().decode('utf-8'))
139141
note = self.__add_simplenote_api_fields(note, noteid, int(response.info().get("X-Simperium-Version")))
@@ -191,7 +193,7 @@ def update_note(self, note):
191193
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
192194
else:
193195
return e, -1
194-
except IOError as e:
196+
except (IOError, BadStatusLine) as e:
195197
return e, -1
196198
note_to_update = json.loads(response.read().decode('utf-8'))
197199
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=[]):
284286
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
285287
else:
286288
return e, -1
287-
except IOError as e:
289+
except (IOError, BadStatusLine) as e:
288290
return e, -1
289291

290292
# get additional notes if bookmark was set in response
@@ -311,7 +313,7 @@ def get_note_list(self, data=True, since=None, tags=[]):
311313
raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
312314
else:
313315
return e, -1
314-
except IOError as e:
316+
except (IOError, BadStatusLine) as e:
315317
return e, -1
316318
note_list = notes["index"]
317319
self.current = response_notes["current"]
@@ -371,7 +373,7 @@ def delete_note(self, note_id):
371373
request.add_header(self.header, self.get_token())
372374
try:
373375
response = urllib2.urlopen(request)
374-
except IOError as e:
376+
except (IOError, BadStatusLine) as e:
375377
return e, -1
376378
except HTTPError as e:
377379
if e.code == 401:

0 commit comments

Comments
 (0)