在Google合作实验室中,URL重定向是否存在read_csv问题?

问题描述 投票:0回答:2

在笔记本电脑上的本地Jupyter笔记本中用熊猫打开以下CSV文件效果很好:

pd.read_csv('http://fonetik.fr/foo.csv')

但是,当我在Google Colab笔记本中尝试同一行代码时,笔记本显示以下错误:

CertificateError                          Traceback (most recent call last)
<ipython-input-27-030762f24a0e> in <module>()

----> 1 df = pd.read_csv('http://fonetik.fr/foo.csv')
 /usr/lib/python3.6/ssl.py in match_hostname(cert, hostname)
   325         raise CertificateError("hostname %r "
   326             "doesn't match either of %s"
--> 327             % (hostname, ', '.join(map(repr, dnsnames))))
   328     elif len(dnsnames) == 1:
   329         raise CertificateError("hostname %r "

CertificateError: hostname 'fonétik.fr' doesn't match either of 'fonetik.fr', 'www.fonetik.fr', 'www.xn--fontik-dva.fr', 'xn--fontik-dva.fr'

我刚刚检查了fonetik.fr证书,它是有效的。因此,我不理解为什么Jupyter Colab会引发此错误。也许是因为IDA服务器与非IDA服务器之间进行了某种重定向?有解决方案吗?

[您可能认为我应该先把foo.csv文件放在Google云端硬盘上,以免将其感染到第三方服务器上。但是,由于我要使用的实际foo.csv太大且太大而无法存储在我的Google云端硬盘中,因此我无法使用此选项。

pandas google-colaboratory idn
2个回答
0
投票

我发现了针对Colab的以下解决方案:!wget https://fonétik.fr/foo.csvpd.read_csv(foo.csv)


0
投票

有时我遇到同样的问题所以我用这种方式它做得太多了(我知道!),但是它有效只需替换您的URL和变量:

 DOWNLOAD_root="https://raw.githubusercontent.com/ageron/handson-ml2/master/"
 Housing_path=os.path.join("datasets","housing")
 Housing_url=DOWNLOAD_root + "datasets/housing/housing.tgz"
 def fetch_housing_data(housing_url=Housing_url, housing_path=Housing_path):
   if not os.path.isdir(housing_path):
     os.makedirs(housing_path)
 tgz_path=os.path.join(housing_path, "housing.tgz")
 urllib.request.urlretrieve(housing_url, tgz_path)
 housing_tgz = tarfile.open(tgz_path)
 housing_tgz.extractall(path=housing_path)
housing_tgz.close()
fetch_housing_data()
def load_housing_data(housing_path=Housing_path):
csv_path = os.path.join(housing_path, "housing.csv")
return pd.read_csv(csv_path)
© www.soinside.com 2019 - 2024. All rights reserved.