Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fetch dependencies behind proxy #657

Closed
FeatCrush opened this issue Jan 26, 2019 · 3 comments
Closed

Cannot fetch dependencies behind proxy #657

FeatCrush opened this issue Jan 26, 2019 · 3 comments
Labels

Comments

@FeatCrush
Copy link
Contributor

It's seems that the http implementation does not support connecting to repositories through proxies.
The get method from the Requests API does support proxy so it should be a manner of passing the right parameters.

Ideas :

  • Passing proxy settings through cli, pip style (-- proxy)
  • Adding configuration file in .pex folder

Tip; you can bypass resolving depencies by using wheels and cache

@jsirois
Copy link
Member

jsirois commented Jan 29, 2019

The workaround for lack of explicit cli support is to export HTTP_PROXY or HTTPS_PROXY environment variables. Support for this is not really documented in urllib, but it is documented in requests: http://docs.python-requests.org/en/master/user/advanced/#proxies.

To use pex with requests, which is generally recommended, use one of:

  1. pip install pex[requests]
  2. pex pex[requests] -cpex -opex-with-requests.pex

To demonstrate there is plumbing for all this:

For pex without requests you'll see something like:

$ HTTPS_PROXY=fail pex -v pytest
pex: Warning, using a UrllibContext which is known to be flaky.
pex: Please build pex with the requests module for more reliable downloads.
pex: Warning, using a UrllibContext which is known to be flaky.
pex: Please build pex with the requests module for more reliable downloads.
pex: Unknown exception encountered: <urlopen error [Errno -5] No address associated with hostname>
...

And for pex with requests:

$ HTTPS_PROXY=fail ./pex-with-requests.pex -v pytest
pex :: Resolving distributions
pex: Unknown exception encountered: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pytest/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f49c25b9cc0>: Failed to establish a new connection: [Errno -5] No address associated with hostname')))
pex: Traceback (most recent call last):
pex:   File "/home/jsirois/.pex/install/urllib3-1.24.1-py2.py3-none-any.whl.7946595476aedeb4b110bd278399646b683a17f4/urllib3-1.24.1-py2.py3-none-any.whl/urllib3/connection.py", line 159, in _new_conn
pex:     (self._dns_host, self.port), self.timeout, **extra_kw)
pex:   File "/home/jsirois/.pex/install/urllib3-1.24.1-py2.py3-none-any.whl.7946595476aedeb4b110bd278399646b683a17f4/urllib3-1.24.1-py2.py3-none-any.whl/urllib3/util/connection.py", line 57, in create_connection
pex:     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
pex:   File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
pex:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
pex: socket.gaierror: [Errno -5] No address associated with hostname
...

Since this is a robust - and once you're in-the-know about the env vars - universal workaround, I'm tempted to close this issue with a documentation update highlighting the env vars. Do you agree that's enough? If so and this works for you, would you be willing to chip in the doc update? Pehaps an addition to recipes would do?: https://github.com/pantsbuild/pex/blob/master/docs/recipes.rst

@FeatCrush
Copy link
Contributor Author

hi, thank you for the explanation.
I've successfully tested this solution in my environment. As you say, it seems that there is no issue and an example in the documentation should be just fine.

To do just that, I initiated the following pull request : #659

@jsirois
Copy link
Member

jsirois commented Jan 30, 2019

Excellent. Thank you @FeatCrush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants