Search code examples
pythonpandasurlopenfancyurlopener

urlopen error [Errno 11001] getaddrinfo failed for a local drive


I am trying to run a code in spyder and it throws error

"     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. 

code is as follows

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()


Thank you in advance


Solution

  • pd.read_csv is interpreting the filename as a URL, not a local path.

    You can open the file yourself, and pass the file object.

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