4

I can't upload to pypi using twine when a proxy server is involved.

That's what I tried so far:

python -m twine upload -u USER -p PASSWORD dist/*

When I'm behind our company proxy server twine just hangs, no error message. Set the https_proxy and thehttp_proxy environment variables doesn't help as well.

Our company proxy server has it's own CA certificate (I've the .cer file).

So how can I use twine behind a proxy server.

With pip I was able to do it by adding the following pip.ini file to %Appdata%\pip:

[global]
proxy = proxy.company.com:8080
cert = C:\CA_Proxy.cer
Wollmich
  • 1,616
  • 1
  • 18
  • 46

2 Answers2

3

I've been able to solve a similar issue under Windows by setting an HTTPS_PROXY environment variable, without having to set anything about certificates.

Working in a cmd prompt, run

set HTTPS_PROXY=proxy.company.com:8080

before running your twine command in the same session.

The environment variable can also be set permanently using the control panel or as described in https://superuser.com/q/79612/1148425

jpeg
  • 2,372
  • 4
  • 18
  • 31
  • It doesn't work: `urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='upload.pypi.org', port=443): Max retries exceeded with url: /legacy/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)'),))` – Wollmich May 15 '20 at 09:53
  • 1
    `set TWINE_CERT=C:\CA_Proxy.pem` solves the problem. Make sure the certificate is in the PEM format. – Wollmich May 15 '20 at 15:19
2

Setting the HTTPS_PROXY and TWINE_CERT environment variables in command prompt before running twine solve the problem:

set HTTPS_PROXY=proxy.company.com:8080
set TWINE_CERT=C:\CA_Proxy.pem

python -m twine upload -u USER -p PASSWORD dist/*

Remark: make sure that the certificate is in the PEM (Base-64 encoded X.509) format.

See the twine user manual for the TWINE_CERT environment variable https://twine.readthedocs.io/en/latest/.

Wollmich
  • 1,616
  • 1
  • 18
  • 46