Debug logging for Imgur upload request

This commit is contained in:
Phin 2024-10-18 00:00:52 +05:30
parent 11ffb01a40
commit 4a7b37bb81

View file

@ -17,11 +17,13 @@ def uploadToImgur(url: str) -> Optional[str]:
newImage.thumbnail((maxSize, maxSize)) newImage.thumbnail((maxSize, maxSize))
newImageBytesIO = io.BytesIO() newImageBytesIO = io.BytesIO()
newImage.save(newImageBytesIO, subsampling = 0, quality = 90, format = "JPEG") newImage.save(newImageBytesIO, subsampling = 0, quality = 90, format = "JPEG")
data: models.imgur.UploadResponse = requests.post( response = requests.post(
"https://api.imgur.com/3/image", "https://api.imgur.com/3/image",
headers = { "Authorization": f"Client-ID {config['display']['posters']['imgurClientID']}" }, headers = { "Authorization": f"Client-ID {config['display']['posters']['imgurClientID']}" },
files = { "image": newImageBytesIO.getvalue() } files = { "image": newImageBytesIO.getvalue() }
).json() )
logger.debug("HTTP %d, %s, %s", response.status_code, response.headers, response.text.strip())
data: models.imgur.UploadResponse = response.json()
if not data["success"]: if not data["success"]:
raise Exception(data["data"]["error"]) raise Exception(data["data"]["error"])
return data["data"]["link"] return data["data"]["link"]