Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encoding = [i[1] for i in result.getheaders() if i[0] == "content-encoding"]
possibly_encoded = result.read()
try:
possibly_encoded = zlib.decompress(possibly_encoded, 16 + zlib.MAX_WBITS)
except Exception:
pass
result.body = self._process_body(
possibly_encoded, len(encoding) and encoding[0] == "gzip"
)
conn.close()
if result.status in (404, 410):
raise HubspotNotFound(result, request)
if result.status == 401:
raise HubspotUnauthorized(result, request)
if result.status == 409:
raise HubspotConflict(result, request)
if result.status == 429:
raise HubspotRateLimited(result, request)
if 400 <= result.status < 500 or result.status == 501:
raise HubspotBadRequest(result, request)
if result.status >= 500:
raise HubspotServerError(result, request)
return result
emergency_brake = 10
try_count = 0
while True:
emergency_brake -= 1
# avoid getting burned by any mistakes in While loop logic
if emergency_brake < 1:
break
try:
try_count += 1
connection = opts["connection_type"](opts["api_base"], **kwargs)
request_info = self._create_request(
connection, method, url, headers, data
)
result = self._execute_request_raw(connection, request_info)
break
except HubspotUnauthorized:
self.log.warning("401 Unauthorized response to API request.")
if (
self.access_token
and self.refresh_token
and self.client_id
and self.client_secret
):
if retried:
self.log.error(
"Refreshed token, but request still was not authorized. "
"You may need to grant additional permissions."
)
raise
from hubspot3.oauth2 import OAuth2Client