mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
Imgur uploads to use requests library
This commit is contained in:
parent
dc25ef857f
commit
ce846d65cb
1 changed files with 16 additions and 15 deletions
|
@ -38,6 +38,7 @@ import xmltodict
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
import logger
|
import logger
|
||||||
|
import request
|
||||||
from plexpy.api2 import API2
|
from plexpy.api2 import API2
|
||||||
|
|
||||||
|
|
||||||
|
@ -702,21 +703,21 @@ def uploadToImgur(imgPath, imgTitle=''):
|
||||||
data['title'] = imgTitle.encode('utf-8')
|
data['title'] = imgTitle.encode('utf-8')
|
||||||
data['name'] = imgTitle.encode('utf-8') + '.jpg'
|
data['name'] = imgTitle.encode('utf-8') + '.jpg'
|
||||||
|
|
||||||
try:
|
response, err_msg, req_msg = request.request_response2('https://api.imgur.com/3/image', 'POST', headers=headers, data=data)
|
||||||
request = urllib2.Request('https://api.imgur.com/3/image', headers=headers, data=urllib.urlencode(data))
|
|
||||||
response = urllib2.urlopen(request)
|
|
||||||
response = json.loads(response.read())
|
|
||||||
|
|
||||||
if response.get('status') == 200:
|
if response and not err_msg:
|
||||||
t = '\'' + imgTitle + '\' ' if imgTitle else ''
|
t = '\'' + imgTitle + '\' ' if imgTitle else ''
|
||||||
logger.debug(u"PlexPy Helpers :: Image %suploaded to Imgur." % t)
|
logger.debug(u"PlexPy Helpers :: Image {}uploaded to Imgur.".format(t))
|
||||||
img_url = response.get('data').get('link', '').replace('http', 'https')
|
img_url = response.json().get('data').get('link', '').replace('http', 'https')
|
||||||
elif response.get('status') >= 400 and response.get('status') < 500:
|
|
||||||
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur: %s" % response.reason)
|
else:
|
||||||
|
if err_msg:
|
||||||
|
logger.error(u"PlexPy Helpers :: Unable to upload image to Imgur: {}".format(err_msg))
|
||||||
else:
|
else:
|
||||||
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur.")
|
logger.error(u"PlexPy Helpers :: Unable to upload image to Imgur.")
|
||||||
except (urllib2.HTTPError, urllib2.URLError) as e:
|
|
||||||
logger.warn(u"PlexPy Helpers :: Unable to upload image to Imgur: %s" % e)
|
if req_msg:
|
||||||
|
logger.debug(u"PlexPy Helpers :: Request response: {}".format(req_msg))
|
||||||
|
|
||||||
return img_url
|
return img_url
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue