man-c / pycoingecko

Python wrapper for the CoinGecko API
MIT License
1.04k stars 268 forks source link

Unhandled exception in exception handler #28

Closed xmatthias closed 3 years ago

xmatthias commented 3 years ago

Request timeouts are handled incorrectly, and will result in an exception of local variable 'response' referenced before assignment.

As a timeout will cause a requests.Timeout exception on the first line of the "try" block, the subsequent exception handler has response undefined.

A better way would probably be to handle the "timeout" exception seperately - or define response before the try block and check if it's defined in the exception handler.

Relevant code:

https://github.com/man-c/pycoingecko/blob/8b7a8451cc8911eff5a7f268c885da4bc1570c3f/pycoingecko/api.py#L23-L38

Unfortunately, reproducing this reliably is quite hard, as timeouts are ... in general not easy to reproduce.

man-c commented 3 years ago

There is already a branch that fixes such issues. It will be merged soon and will be included in the new release.

Thanks for reporting!