Catch HTTP errors for Imgur upload

This commit is contained in:
JonnyWong16 2016-02-21 09:33:31 -08:00
parent ca29333cd0
commit bc42e79bb5

View file

@ -546,6 +546,7 @@ def uploadToImgur(imgPath, imgTitle=''):
data['title'] = imgTitle
data['name'] = imgTitle + '.jpg'
try:
request = urllib2.Request('https://api.imgur.com/3/image', headers=headers, data=urllib.urlencode(data))
response = urllib2.urlopen(request)
response = json.loads(response.read())
@ -557,5 +558,7 @@ def uploadToImgur(imgPath, imgTitle=''):
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur: %s" % response.reason)
else:
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur.")
except urllib2.HTTPError as e:
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur: %s" % e)
return img_url