mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 13:11:15 -07:00
Update cloudinary to 1.20.0
This commit is contained in:
parent
1c56d9c513
commit
2984629b39
27 changed files with 2865 additions and 923 deletions
43
lib/cloudinary/http_client.py
Normal file
43
lib/cloudinary/http_client.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
import json
|
||||
import socket
|
||||
|
||||
import certifi
|
||||
from urllib3 import PoolManager
|
||||
from urllib3.exceptions import HTTPError
|
||||
|
||||
from cloudinary.exceptions import GeneralError
|
||||
|
||||
|
||||
class HttpClient:
|
||||
DEFAULT_HTTP_TIMEOUT = 60
|
||||
|
||||
def __init__(self, **options):
|
||||
# Lazy initialization of the client, to improve performance when HttpClient is initialized but not used
|
||||
self._http_client_instance = None
|
||||
self.timeout = options.get("timeout", self.DEFAULT_HTTP_TIMEOUT)
|
||||
|
||||
@property
|
||||
def _http_client(self):
|
||||
if self._http_client_instance is None:
|
||||
self._http_client_instance = PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
|
||||
return self._http_client_instance
|
||||
|
||||
def get_json(self, url):
|
||||
try:
|
||||
response = self._http_client.request("GET", url, timeout=self.timeout)
|
||||
body = response.data
|
||||
except HTTPError as e:
|
||||
raise GeneralError("Unexpected error %s" % str(e))
|
||||
except socket.error as e:
|
||||
raise GeneralError("Socket Error: %s" % str(e))
|
||||
|
||||
if response.status != 200:
|
||||
raise GeneralError("Server returned unexpected status code - {} - {}".format(response.status,
|
||||
response.data))
|
||||
try:
|
||||
result = json.loads(body.decode('utf-8'))
|
||||
except Exception as e:
|
||||
# Error is parsing json
|
||||
raise GeneralError("Error parsing server response (%d) - %s. Got - %s" % (response.status, body, e))
|
||||
|
||||
return result
|
Loading…
Add table
Add a link
Reference in a new issue