lastfm: handle http.client.BadStatusLine
parent
04c41d07ed
commit
60660c1755
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue