conda / constructor

tool for creating installers from conda packages
https://conda.github.io/constructor/
Other
460 stars 167 forks source link

Constructor does not respect proxy settings from Conda #304

Closed wattse closed 2 years ago

wattse commented 5 years ago

I'm attempting to use constructor v3, but it fails to use proxy settings specified in my .condarc file. I'm running on win64, conda version is 4.7.12, constructor version is 3.0.

The initial error messages were the standard proxy warning messages:

(constructor) C:\temp\constructor>constructor --conda-exe E:\Programs\anaconda3\envs\constructor\Scripts\conda
.exe .
platform: win-64
Collecting package metadata (repodata.json): failed
Traceback (most recent call last):
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\urllib3\connection.py", line 159, in _new_con
n
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\urllib3\util\connection.py", line 57, in crea
te_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "E:\Programs\anaconda3\envs\constructor\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

<SNIP>

  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\conda\core\subdir_data.py", line 90, in <lambda>
    package_ref_or_match_spec))
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\conda\core\subdir_data.py", line 102, in query
    self.load()
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\conda\core\subdir_data.py", line 166, in load
    _internal_state = self._load()
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\conda\core\subdir_data.py", line 240, in _load
    repodata_fn=self.repodata_fn)
  File "E:\Programs\anaconda3\envs\constructor\lib\site-packages\conda\core\subdir_data.py", line 587, in fetch_repodata_remote_request
    caused_by=e)
conda.exceptions.CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file a support request with your network engineering team.

ConnectionError(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/win-64/repodata.json (Caused by newConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000000005B08DA0>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',)
)",),)

I placed some debug print statements in CondaSession (conda/gateways/connection/session.py) to check if the proxy information is passing through with constructor. It isn't. The same debug print statements work for a standard conda install command, correctly providing

<frozendict {'http': 'http://localhost:3129', 'https': 'https://localhost:3129'}>

as the relevant proxy interfaces (cntlm). For a constructor call, the output is

<frozendict {}>

Somewhere, constructor is ignoring some of the .condarc settings. I'm currently forcing my proxy settings in a conda env to make this work by editing conda/gateways/connection/session.py, line 67ish:

        context.proxy_servers = {'http': 'http://localhost:3129', 'https': 'https://localhost:3129'}
        self.proxies.update(context.proxy_servers)
mcg1969 commented 4 years ago

Thanks for the report (and apologies for the delay). I've been doing some issue pruning here so that genuine issues like yours will bubble to the top.

mcg1969 commented 4 years ago

I don't have an easy way to reproduce this. Can someone else give it a shot?

gabrielcnr commented 4 years ago

@mcg1969 I'm also having the same problem because I'm using constructor in a company where all the HTTP access is behind proxies. To reproduce this simply execute conda config --set proxy_servers.no_proxy https://foo/ and then invoke constructor. It's easy to observe if you have two breakpoints in the main function of fcp.py module, one before, and after the call to the context manager:

print(f"before: {conda_context.proxy_servers}")  # good
breakpoint()  # or import pdb; pdb.set_trace()
with env_vars({
        "CONDA_PKGS_DIRS": download_dir,
    }, conda_replace_context_default):
    print(f"after: {conda_context.proxy_servers}")  # bad (blanked out)
    breakpoint()  # or import pdb; pdb.set_trace()
gabrielcnr commented 4 years ago

Also, my .condarc has a configuration for ssl_verify pointing to a .pem file in disk. Before the context manager that value is correctly set in the conda_context, containing the path to the file, but inside the context manager that value is lost and replaced with boolean True, which also causes problems.

mcg1969 commented 4 years ago

Thanks for the fix @gabrielcnr !

github-actions[bot] commented 2 years ago

Hi there, thank you for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue at hand
  2. Comment that the issue is still reproducible and include:
    • What OS and version you reproduced the issue on
    • What steps you followed to reproduce the issue

NOTE: If this issue was closed prematurely, please leave a comment.

Thanks!