otteheng
otteheng

Reputation: 604

OSError: [Errno 22] Invalid argument: (Read file from Github)

I have a geojson file stored on my laptop and on github. I have no trouble reading the file off of my laptop:

obj = r'Teacher Quality Gap - Washington\Geo\1988\experience_gap_bins_0.102-0.805.geojson'
with open(obj) as f:
    geo = json.load(f)

But when I read this from github I get an OSError.

base_url = 'https://raw.githubusercontent.com/otteheng/Teacher-Quality-Gaps-Dash/master/'

year = '1988'
binz = 'experience_gap_bins_0.102-0.805'
with open(base_url + year + '/' + binz + '.geojson?_sm_au_=iMV8R4JMtDJsZNt2') as f:
    geo = json.load(f)

What am I doing wrong? I'm using Python 3.6 on windows.

Upvotes: 1

Views: 1315

Answers (1)

Horia Coman
Horia Coman

Reputation: 8781

open can only open local files. Or more precisely, files from a filesystem accessible to the running process (so a network mounted filesystem would still be accessible). It can't "open" files from a http server or ftp server etc. Like you're trying to do.

Check out the requests package for something which can do what you're trying to do.

Upvotes: 2

Related Questions