gpt4 book ai didi

python - 如何使用 Python 从 RESTful 服务获取 JSON 数据?

转载 作者:IT老高 更新时间:2023-10-28 12:43:06 31 4
gpt4 key购买 nike

有没有使用 Python 从 RESTful 服务获取 JSON 数据的标准方法?

我需要使用 kerberos 进行身份验证。

一些片段会有所帮助。

最佳答案

我会给 requests图书馆尝试一下。本质上只是一个更容易使用的标准库模块(即 urllib2、httplib2 等)的包装器,您将用于相同的事情。例如,从需要基本身份验证的 url 获取 json 数据如下所示:

import requests

response = requests.get('http://thedataishere.com',
auth=('user', 'password'))
data = response.json()

对于 kerberos 身份验证,requests projectreqests-kerberos提供 kerberos 身份验证类的库,您可以将其与 requests 一起使用:

import requests
from requests_kerberos import HTTPKerberosAuth

response = requests.get('http://thedataishere.com',
auth=HTTPKerberosAuth())
data = response.json()

关于python - 如何使用 Python 从 RESTful 服务获取 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7750557/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com