Improve pypi search error handling.

Fixes #1126