简体   繁体   English

使用 python 通过 URL 获取数据文件时发生错误

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

相关问题 使用字符串输入在Python中遍历多个文件时出现“ IO错误:否此类文件或目录”? - Getting 'IO Error: No Such file or directory' when using string input to loop through multiple files in Python? 带有数据的 Python 3D 绘图,发生错误 - Python 3D plot with data, error occured 使用tkinter列表框时发生令人困惑的错误 - confusing error occured when using tkinter listbox 使用df.fillna(0)时发生错误 - error occured when using df.fillna(0) 而网络抓取循环通过每个 url 为每个 url 数据生成一个单独的文本文件得到错误 - while web-scraping looping through each url to make a separate text file for every url data getting error 出现错误:FileNotFoundError: [Errno 2] No such file or directory when using Python open() - Getting error: FileNotFoundError: [Errno 2] No such file or directory when using Python open() 使用python和pandas读取Yahoo数据时出现错误 - getting an error when reading yahoo data using python and pandas 使用python将文件读入字典时出现Value错误 - Getting Value error when reading file into a dictionary using python 使用python和arcpy删除地理数据库中的数据时出现错误 - Getting an error when using python and arcpy to delete data in a geodatabase 使用 python 从 url 获取数据并解压缩 - Getting data from the url using python and unzipped
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM