alex9smith / gdelt-doc-api

A Python client for the GDELT 2.0 Doc API
MIT License
100 stars 23 forks source link

Catch API errors when a query string is invalid #20

Closed alex9smith closed 2 years ago

alex9smith commented 2 years ago

When a query produces an invalid query string, the API returns a plain text error message. These were being converted into bytes and then tried to parse as JSON which was failing and returned the cryptic error message TypeError: argument of type 'int' is not iterable.

When the API returns valid results it uses an application/json content type, so check the content type of the response and if it's text/html raise an error and display the API error message to the user.

Mostly addresses #18