[英]Error occured when getting the data file through URL using python
I tried to load data from a URL我试图从 URL 加载数据
url = 'http://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
chipo = pd.read_csv(url, sep = '\t')
and there is an error并且有一个错误
URLError: <urlopen error [Errno 11004] getaddrinfo failed>
I've checked this answer but this does not help.我已经检查了这个答案,但这没有帮助。
I've also tried fetching data using requests
and the error occured again我也尝试过使用
requests
获取数据,错误再次发生
ConnectionError: HTTPConnectionPool(host='raw.githubusercontent.com', port=80): Max retries exceeded with url: /justmarkham/DAT8/master/data/chipotle.tsv (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000029B29E43748>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))
It seems that there is something wrong with DNS so I edited the hosts file but it does not help either. DNS 似乎有问题,所以我编辑了主机文件,但它也无济于事。 How should I fix this problem?
我应该如何解决这个问题?
Thanks a lot.非常感谢。
Case solved.案子解决了。 It turns out to be the problem of the DNS and I need the proxy to get access to the resources.
原来是 DNS 的问题,我需要代理才能访问资源。 This could explain why this problem is not reproducible.
这可以解释为什么这个问题是不可重现的。
import socket
import socks
socks.set_default_proxy(socks.SOCKS5, '127.0.0.1', 10808)
socket.socket = socks.socksocket
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
chipo = pd.read_csv(url, sep = '\t')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.