如何将 JSON Web 服务/Web Api 与我们的 python 程序集成以及 程序应在运行时从配置文件获取配置设置
import urllib.request
a_url = 'http://www.w3.org/2005/Atom'
data = urllib.request.urlopen(a_url).read()
print(data)
我找到了这段代码,关于我的问题。这是正确的方法吗? 请帮我解决这个问题。
最佳答案
您可以使用requests
,没有一个理智的人会使用 urllib。
安装它:
$ pip install requests
然后像这样使用它:
import requests a_url = 'http://www.w3.org/2005/Atom' response = requests.get(a_url) response.status_code # 200 response.text # html of the webpage # response.json() # only if the url responds with json data, otherwise it will throw error
关于python - Python 中的 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57336798/