fix: upload_image parses response body before checking HTTP status (#22475)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions

* fix: check HTTP response status before parsing JSON body

upload_image() calls r.json() before checking r.ok. If the server
returns an error response (401, 500, etc) with a non-JSON body,
this raises a confusing JSONDecodeError instead of the intended
'Unable to get signed urls' error message.

Move the r.ok check before the r.json() call.

* style: remove extra blank line for ruff
This commit is contained in:
ryzendigo 2026-03-17 07:34:30 +08:00 committed by GitHub
parent 7708523865
commit dc27d4ad16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -105,9 +105,9 @@ class PlusApi:
def upload_image(self, image: ndarray, camera: str) -> str:
r = self._get("image/signed_urls")
presigned_urls = r.json()
if not r.ok:
raise Exception("Unable to get signed urls")
presigned_urls = r.json()
# resize and submit original
files = {"file": get_jpg_bytes(image, 1920, 85)}