lightly-ai / lightly

A python library for self-supervised learning on images.
https://docs.lightly.ai/self-supervised-learning/
MIT License
3.09k stars 264 forks source link

Respect HTTP proxy environment variables #1492

Closed benz0li closed 8 months ago

benz0li commented 8 months ago

@japrescott As already explained in my emails:

One can configure urllib3.PoolManager’s ca_certs via environment variable LIGHTLY_CA_CERTS.

  1. https://github.com/lightly-ai/lightly/blob/715844b89335adcebfabc4e5c124706f47435dc6/lightly/api/utils.py#L225-L242
  2. https://github.com/lightly-ai/lightly/blob/715844b89335adcebfabc4e5c124706f47435dc6/lightly/openapi_generated/swagger_client/rest.py#L83-L105

But as long as configuration.proxy remains unset, there is no way that urllib3.ProxyManager (and thus a HTTP Proxy) is used.


Not only configuration.ssl_ca_cert but also configuration.proxy should be settable via an environment variable to fully support running behind a corporate proxy/firewall.

Usually this is done by common environment variables like HTTP_PROXY, HTTPS_PROXY, ALL_PROXY (or their lowercase counterparts).

FYI @IgorSusmelj @nasserdr

benz0li commented 8 months ago

Current workaround for the Lightly worker: Mounting a patched rest.py to /home/boris/openapi/build/swagger_client/swagger_client/rest.py.

Patch: Inserting configuration.proxy = "http://<host>:<port>" just before https://github.com/lightly-ai/lightly/blob/715844b89335adcebfabc4e5c124706f47435dc6/lightly/openapi_generated/swagger_client/rest.py#L83-L85

japrescott commented 8 months ago

Hey @benz0li Thanks a lot for opening a issue. The proxy variable will need to be set within the get_api_client_configuration fn. Will open a PR later today