The 502 response was not caused by a network issue. I am using jenkins credentials to store the API key and something went wrong with that. And the incorrect API key resulted in the 502 (Bad Gateway) error.
This combined with the fact that the same command (but using the correct API key) from the same system with the same user did work caused great confusion.
I hope you (Sonatype) can fix it so that an incorrect/expired API key will return 401 (Unauthorized) instead of 502 (Bad Gateway). That would have pointed me in the right direction!