[英]Log into Corporate Proxy Server with Python to Pull Data
I am trying to pull data from Quandl through Python.我正在尝试通过 Python 从 Quandl 中提取数据。 The problem I run into is that my Corporate's proxy blocks my ability to pull the data.我遇到的问题是我公司的代理阻止了我提取数据的能力。 Is there a way to log in to the proxy within the code itself by providing my username and password?有没有办法通过提供我的用户名和密码在代码本身内登录到代理?
I am very new to Python/coding-in-general, and any help is greatly appreciated!我对 Python/一般编码非常陌生,非常感谢任何帮助! I am using Python 3.5.我正在使用 Python 3.5。
My code:我的代码:
from Quandl import Quandl
mydata = Quandl.get("FRED/GDP")
Output:输出:
URLError: <urlopen error Tunnel connection failed: 407 Proxy Authentication Required>
Add the following lines to your code, to provide your proxy settings [1]:将以下行添加到您的代码中,以提供您的代理设置 [1]:
import os
os.environ['HTTP_PROXY'] = "http://username:password@proxyAddress:portNumber"
os.environ['HTTPS_PROXY'] = "https://username:password@proxyAddress:portNumber"
After that, if you encounter the 465 certificate error you might choose to remove the ssl verification as follows [2]:之后,如果您遇到 465 证书错误,您可以选择删除 ssl 验证,如下所示 [2]:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
For IPython, you might need to restart your kernel or reconnect to it for the changes to take effect.对于 IPython,您可能需要重新启动内核或重新连接到它以使更改生效。
You can check the current proxy settings with:您可以通过以下方式检查当前的代理设置:
import urllib
urllib.request.getproxies_environment()
[1]. [1]。 https://www.jayakumar.org/linux/how-to-configure-httphttps-proxy-for-ipython-notebook-server/ [2]. https://www.jayakumar.org/linux/how-to-configure-httphttps-proxy-for-ipython-notebook-server/ [2]。 https://stackoverflow.com/a/28052583/4924665 https://stackoverflow.com/a/28052583/4924665
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.