OSError:[Errno 22]参数无效:(从Github读取文件)

时间:2018-03-19 17:58:35

标签: python

我的笔记本电脑和github上存储了一个geojson文件。我从笔记本电脑上读取文件没有问题:

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)

但是当我从github读到这封信时,我得到了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)

我做错了什么?我在Windows上使用Python 3.6。

1 个答案:

答案 0 :(得分:2)

open只能打开本地文件。或者更确切地说,来自正在运行的进程可访问的文件系统的文件(因此仍然可以访问网络安装的文件系统)。它无法打开"来自http服务器或ftp服务器等的文件。就像您尝试做的那样。

查看requests软件包,了解可以执行您尝试做的事情。