猿问

urlopen 错误 [Errno 11001] 本地驱动器的 getaddrinfo 失败

我正在尝试在 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()


一只名叫tom的猫
浏览 880回答 1
1回答

郎朗坤

pd.read_csv将文件名解释为 URL,而不是本地路径。您可以自己打开文件,并传递文件对象。with&nbsp;open(os.path.join(root,&nbsp;fname))&nbsp;as&nbsp;f: &nbsp;&nbsp;&nbsp;&nbsp;df&nbsp;=&nbsp;pd.read_csv(f)
随时随地看视频慕课网APP

相关分类

Python
我要回答