【问题标题】:urlopen error [Errno 11001] getaddrinfo failed for a local driveurlopen 错误 [Errno 11001] 本地驱动器的 getaddrinfo 失败
【发布时间】:2020-01-28 03:09:59
【问题描述】:

我正在尝试在 spyder 中运行代码并引发错误

"     return self.do_open(http.client.HTTPConnection, req)

  File "C:\Users\name\AppData\Local\Continuum\Anaconda3-5.2.0\lib\urllib\request.py", line 1320, in do_open
    raise URLError(err)

URLError: <urlopen error [Errno 11001] getaddrinfo failed>"
same code works fine in jupyter notebook. 

代码如下

import overpy
import pandas as pd
import time
import os


root = r'C:/Users/(name)/Documents/abc'
fstem = 'sample'
fname = fstem+'.csv'
df = pd.read_csv(os.path.join(root,fname))
#df.sort_values(by=['cvdt35_timestamp_s'],inplace=True)
print('# of records = '+str(len(df)))
api= overpy.Overpass()


提前谢谢你

【问题讨论】:

  • 为什么在路径中使用/ 而不是\?
  • @Trapli Windows 允许。

标签: python pandas urlopen fancyurlopener


【解决方案1】:

pd.read_csv 将文件名解释为 URL,而不是本地路径。

您可以自己打开文件,并传递文件对象。

with open(os.path.join(root, fname)) as f:
    df = pd.read_csv(f)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    相关资源
    最近更新 更多