plexpy/lib/cloudinary/http_client.py
dependabot[bot] 6c6fa34ba4
Bump cloudinary from 1.34.0 to 1.39.1 (#2283)
* Bump cloudinary from 1.34.0 to 1.39.1

Bumps [cloudinary](https://github.com/cloudinary/pycloudinary) from 1.34.0 to 1.39.1.
- [Release notes](https://github.com/cloudinary/pycloudinary/releases)
- [Changelog](https://github.com/cloudinary/pycloudinary/blob/master/CHANGELOG.md)
- [Commits](https://github.com/cloudinary/pycloudinary/compare/1.34.0...1.39.1)

---
updated-dependencies:
- dependency-name: cloudinary
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update cloudinary==1.39.1

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>

[skip ci]
2024-03-24 15:27:42 -07:00

44 lines
1.6 KiB
Python

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(method="GET", url=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