lastfm: handle http.client.BadStatusLine

master
mutantmonkey 2011-09-26 14:11:48 -04:00
parent 04c41d07ed
commit 60660c1755
1 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,7 @@ author: Casey Link <unnamedrambler@gmail.com>
import random import random
import configparser, os import configparser, os
import http.client
from urllib.parse import quote as urlquote from urllib.parse import quote as urlquote
from urllib.request import urlopen from urllib.request import urlopen
from urllib.error import HTTPError from urllib.error import HTTPError
@ -92,6 +93,9 @@ def now_playing(phenny, input):
else: else:
phenny.say("uhoh. try again later, mmkay?") phenny.say("uhoh. try again later, mmkay?")
return return
except http.client.BadStatusLine:
phenny.say("uhoh. try again later, mmkay?")
return
doc = etree.parse(req) doc = etree.parse(req)
root = doc.getroot() root = doc.getroot()
recenttracks = list(root) recenttracks = list(root)
@ -152,7 +156,7 @@ def aep(phenny, input):
user = user.strip() user = user.strip()
try: try:
req = urlopen("%s%s" % (AEPURL, urlquote(user))) req = urlopen("%s%s" % (AEPURL, urlquote(user)))
except HTTPError as e: except (HTTPError, http.client.BadStatusLine) as e:
phenny.say("uhoh. try again later, mmkay?") phenny.say("uhoh. try again later, mmkay?")
return return
result = req.read() result = req.read()
@ -183,7 +187,7 @@ def tasteometer(phenny, input):
user2 = input.nick user2 = input.nick
try: try:
req = urlopen("%smethod=tasteometer.compare&type1=user&type2=user&value1=%s&value2=%s" % (APIURL, urlquote(user1), urlquote(user2))) req = urlopen("%smethod=tasteometer.compare&type1=user&type2=user&value1=%s&value2=%s" % (APIURL, urlquote(user1), urlquote(user2)))
except HTTPError as e: except (HTTPError, http.client.BadStatusLine) as e:
if e.code == 400: if e.code == 400:
phenny.say("uhoh, someone doesn't exist on last.fm, perhaps they need to set user") phenny.say("uhoh, someone doesn't exist on last.fm, perhaps they need to set user")
return return