在提取数据或连接到主机时,我无法连接到互联网。我当前的项目涉及在Python 3.6中使用plot.ly(plotly)创建一个Choropleth和网络图。我已成功按照他们的文档离线创建了网络图。
由于没有Choropleth离线方法,因此我使用以下内容读取数据:
import urllib
urllib.request.urlopen('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')
然后我遇到以下错误消息:
urllib.error.URLError: <urlopen error [WinError 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>
我正在通过代理在远程服务器上运行。我已经为HTTP_PROXY和HTTPS_PROXY创建了环境变量。此外,如果输入以下命令,我将获得正确的代理服务器
: urllib.request.getproxies()
关于连接到主机以获取在线网络图,如果我键入:
import urllib3
import certifi
from urllib3 import ProxyManager, make_headers
default_headers = urllib3.make_headers(proxy_basic_auth =
'username:password')
http = urllib3.ProxyManager('http://proxy:port/',
headers = default_headers)
r = http.request('GET', 'http://plot.ly')
import plotly.plotly as py
import plotly.graph_objs as go
import plotly
plotly.tools.set_credentials_file(username='plotlyuser',
api_key='plotlyapikey')
plotly.tools.set_config_file(world_readable = False, sharing = 'private')
trace0 = go.Scatter(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[16, 5, 11, 9]
)
data = [trace0, trace1]
py.plot(data, filename = 'basic-line', auto_open=True)
我得到以下错误代码(除以上最后一行外,所有代码都运行正常):
TimeoutError: [WinError 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
urllib3.exceptions.NewConnectionError:
<urllib3.connection.VerifiedHTTPSConnection object at 0x000000292C437780>:
Failed to establish a new connection: [WinError 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
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='plot.ly',
port=443): Max retries exceeded with url: /clientresp (Caused by
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at
0x000000292C437780>: Failed to establish a new connection: [WinError 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'))
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='plot.ly',
port=443): Max retries exceeded with url: /clientresp (Caused by
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at
0x000000292C437780>: Failed to establish a new connection: [WinError 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'))
plotly.exceptions.PlotlyRequestError: No message
很抱歉,这个问题很长,但是一段时间以来,我一直在努力解决这个问题!