无法将python配置为代理 [英] Unable to configure python to proxy

查看:32
本文介绍了无法将python配置为代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与我的问题相关的早期帖子都无法为我提供解决方案.所以我在一个新线程中发帖.

None of the earlier posts related to my question below were able to provide me a solution. So i am posting in a new thread.

我通过我大学中经过身份验证的代理连接到互联网.所以在浏览器中,我提供了我的用户名密码.但是我无法在python中下载数据.

I connect to the internet thru an authenticated proxy in my university. So in browsers, i give in my username password. However i am unable to download data in python.

我在python 2.7中输入了以下4行来下载数据.我已经成功安装了 pandas 和 datetime 库;所以下面的前两行没有问题.

i entered the following 4 lines in python 2.7 to download data. i have successfully installed pandas and datetime libraries; so the first 2 lines below have no problems.

from pandas.io.data import DataReader
from datetime import datetime
goog = DataReader("GOOG",  "yahoo", datetime(2000,1,1), datetime(2012,1,1))
print goog["Adj Close"]

我得到的错误如下:

Traceback (most recent call last):
File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 3, in  <module>
pass
File "C:\Python27\Lib\site-packages\pandas\io\data.py", line 53, in DataReader
return get_data_yahoo(name=name, start=start, end=end)
File "C:\Python27\Lib\site-packages\pandas\io\data.py", line 134, in get_data_yahoo
lines = urllib.urlopen(url).read()
File "C:\Python27\Lib\urllib.py", line 86, in urlopen
return opener.open(url)
File "C:\Python27\Lib\urllib.py", line 211, in open
return getattr(self, name)(url)
File "C:\Python27\Lib\urllib.py", line 344, in open_http
h.endheaders(data)
File "C:\Python27\Lib\httplib.py", line 954, in endheaders
self._send_output(message_body)
File "C:\Python27\Lib\httplib.py", line 814, in _send_output
self.send(msg)
File "C:\Python27\Lib\httplib.py", line 776, in send
self.connect()
File "C:\Python27\Lib\httplib.py", line 757, in connect
self.timeout, self.source_address)
File "C:\Python27\Lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno 11004] getaddrinfo failed

有什么线索吗??

推荐答案

对于 Windows 7:

For Windows 7:

  1. 右键单击Computer,然后选择Properties
  2. 在左侧,选择高级系统设置
  3. 点击Advanced标签,然后点击Environment Variables
  4. 点击User Variables
  5. 下的New..
  6. 变量名中输入HTTP_PROXY,在变量值中输入http://username:password@proxy.com:port(其中 proxy.com 是代理的主机名或 IP 地址,port 是它的端口 - 从 Internet Explorer 获取)
  7. 依次单击确定"、确定"和确定"以关闭所有对话框.
  1. Right click on Computer, and select Properties
  2. On the left, select Advanced system settings
  3. Click on the Advanced tab, then click Environment Variables
  4. Click on New.. under User Variables
  5. In Variable name, type HTTP_PROXY and in Variable value, type http://username:password@proxy.com:port (where proxy.com is the hostname or IP address of your proxy, and port is the port for it - grab it from Internet Explorer)
  6. Click OK, then OK, then OK again to dismiss all the dialog boxes.

现在,当您打开一个new 命令终端时,Python 应该能够访问 Internet;和任何 IDE(再次启动),应该允许 Python 访问 Internet.

Now, when you open a new command terminal, Python should be able to access the Internet; and any IDE (once started again), should allow Python to access the Internet.

对于 Windows XP,当您右键单击 My Computer 并选择 Properties 时,您将到达单击 Advanced<的相同对话框/code> 标签.

For Windows XP, when you right click on My Computer and select Properties, you'll reach the same dialog box where you click on the Advanced tab.

Python 将在尝试连接到 Internet 之前读取 HTTP_PROXYHTTPS_PROXY 环境变量(如果已设置).如果您使用代理并且缺少这些变量,则任何 Python 应用程序(除非特别豁免)都无法访问 Internet.因此,例如,您将无法 pip install - 但是一旦您设置了这两个变量,Python 将使用代理,然后将连接到 Internet.

Python will read HTTP_PROXY and HTTPS_PROXY enivronment variables (if set) before it tries to connect to the Internet. If you are using a proxy and these variables are missing, any Python application (unless specifically exempted) cannot access the Internet. So, you won't be able to pip install for example - but once you set both of those variables, Python will use the proxy and then will connect to the Internet.

这篇关于无法将python配置为代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆