【发布时间】:2021-01-29 01:35:45
【问题描述】:
我正在尝试访问一个 json 对象,该对象作为压缩 gz 存储在 html 网站上。如果可能的话,我想直接用 urllib 来做这个。
这是我尝试过的:
import urllib
import json
#get the zip file
test = urllib.request.Request('http://files.tmdb.org/p/exports/movie_ids_01_27_2021.json.gz')
#unzip and read
with gzip.open(test, 'rt', encoding='UTF-8') as zipfile:
my_object = json.loads(zipfile)
但这失败了:
TypeError: filename must be a str or bytes object, or a file
是否可以这样直接读取json(例如我不想在本地下载)。
谢谢。
【问题讨论】:
标签: json python-3.x urllib