You did not import the name urlopen.
Since you are using python3, you'll need urllib.request:
from urllib.request import urlopen
req = urlopen(...)
or explicitly referring to the request module
import urllib.request
req = request.urlopen(...)
in python2 this would be
from urllib import urlopen
or use urllib.urlopen.
Note: You are also overriding the name json which is not a good idea.
本文详细介绍了在Python3中如何正确导入并使用urlopen函数。针对不同情况,提供了从urllib.request导入urlopen的方法,以及直接导入urllib.request模块的使用方式。同时提醒读者避免覆盖内置的json名称。

10万+





