gpt4 book ai didi

python - 从代理服务器后面使用 ez_setup.py 安装 Python 的 easy_install

转载 作者:太空狗 更新时间:2023-10-29 17:37:53 25 4
gpt4 key购买 nike

在使用代理服务器的公司网络上,有没有办法使用 ez_setup.py 安装 Python 的 easy_install?目前,我收到连接超时:

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "C:\jsears\python\ez_setup.py", line 278, in <module>
main(sys.argv[1:])
File "C:\jsears\python\ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "C:\jsears\python\ez_setup.py", line 158, in download_setuptools
src = urllib2.urlopen(url)
File "C:\jsears\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\jsears\Python27\lib\urllib2.py", line 400, in open
response = self._open(req, data)
File "C:\jsears\Python27\lib\urllib2.py", line 418, in _open
'_open', req)
File "C:\jsears\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\jsears\Python27\lib\urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\jsears\Python27\lib\urllib2.py", line 1177, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

最佳答案

在 Windows 7 上,使用 PowerShell 时,上述代理设置将被忽略,该工具将无法运行。但我找到了解决方案。

我通过添加修改例程download_file_powershell

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials;

在用于通过 WebClient 类下载的小脚本中。现在是完整的 download_file_powershell 函数:

def download_file_powershell(url, target):
"""
Download the file at url to target using Powershell (which will validate
trust). Raise an exception if the command cannot complete.
"""
target = os.path.abspath(target)
cmd = [
'powershell',
'-Command',
"[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; (new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(),
]
subprocess.check_call(cmd)

关于python - 从代理服务器后面使用 ez_setup.py 安装 Python 的 easy_install,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13733375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com