简体   繁体   English

用Python登录企业代理服务器拉取数据

[英]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.

相关问题 在cntlm公司代理中使用python-requests - using python-requests with cntlm corporate proxy 公司代理下的Python URL请求 - Python URL Request under corporate proxy 企业代理可以在C#中工作,但不能在Python中工作 - Corporate Proxy works in C# but not in Python 无法通过python中的公司代理将正确的凭据传递给服务器,但能够在R中做到这一点 - Unable to pass proper credentials to server through corporate proxy in python, but able to do it in R 使用企业代理后面的python脚本下载文件 - Download File using python script behind corporate proxy 如何在公司代理后面使用带有 python-selenium 的 browsermob? - How to use browsermob with python-selenium behind a corporate proxy? python企业防火墙代理407身份验证所需的错误 - python corporate firewall proxy 407 authentication required error 通过Python中的代理将XML数据发布到服务器 - POST XML data to server via proxy in Python FTP 服务器未使用 sockets 将数据发送到 Python 中的代理 - FTP server not sending data to proxy in Python with sockets 在公司代理后面安装 ibm_db 时 Errno 111 Connection denied (DB2 with Python3) - Errno 111 Connection refused when installing ibm_db behind corporate proxy (DB2 with Python3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM