You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting the following traceback (trimmed from pytest run) when pygbif gets a HTTP 204 error back from the GBIF API. According to the documentation, maps.map() returns a GbifMap object and doesn't raise any exceptions. What I'm seeing it it blowing up instead.
Here's a command that triggers it for me now: pygbif.maps.map(z=10, x=10, y=10). It appears that the API is returning a 204 when there's no data to return for a query. Unfortunately, there's no upstream documentation on what HTTP status codes are allowed for the mapping API, so I puzzled out that this is probably when there aren't any occurrences of the taxon to show, but I also seemed to get it in possible error cases.
This is caused by not checking if there was actually a PNG received from the API before opening it:
The API responds saying that the content type is image/png (not png as the code above incorrectly assumes), but has no Content-Length header and a 0 byte body. The API returning an invalid PNG file is an API issue, it shouldn't do that, but that case should also be checked for.
Versions:
Python: 3.8.12 (old, needed for another dependency)
pygbif: 0.6.0
pillow: 8.3.2
The text was updated successfully, but these errors were encountered:
I'm getting the following traceback (trimmed from pytest run) when pygbif gets a HTTP 204 error back from the GBIF API. According to the documentation,
maps.map()
returns aGbifMap
object and doesn't raise any exceptions. What I'm seeing it it blowing up instead.Here's a command that triggers it for me now:
pygbif.maps.map(z=10, x=10, y=10)
. It appears that the API is returning a 204 when there's no data to return for a query. Unfortunately, there's no upstream documentation on what HTTP status codes are allowed for the mapping API, so I puzzled out that this is probably when there aren't any occurrences of the taxon to show, but I also seemed to get it in possible error cases.This is caused by not checking if there was actually a PNG received from the API before opening it:
pygbif/pygbif/maps/map.py
Line 192 in 1508ca9
The API responds saying that the content type is
image/png
(notpng
as the code above incorrectly assumes), but has noContent-Length
header and a 0 byte body. The API returning an invalid PNG file is an API issue, it shouldn't do that, but that case should also be checked for.Versions:
Python: 3.8.12 (old, needed for another dependency)
pygbif: 0.6.0
pillow: 8.3.2
The text was updated successfully, but these errors were encountered: