Puppet forge API 没有 return 预期 JSON
Puppet forge API does not return expected JSON
我正在尝试访问 Puppet Forge API 以查找最新版本的模块,以便将这些版本与我们当前的 Puppetfile 中的版本进行比较。
作为访问 APIs 的完全新手,但是,我所知道的与 Forge 文档假设我所知道的之间存在差距,所以我一无所获。
https://forgeapi.puppet.com 的文档告诉我:
The API is accessed over HTTPS via the forgeapi.puppetlabs.com domain.
All data is returned in JSON format.
但是,我找不到任何 JSON 格式的数据。
我有一个简单的 Python 脚本用于连接服务器:
import requests
r=requests.get("https://forgeapi.puppet.com")
print(r.status_code)
print(r.headers['content-type'])
内容类型是 text/html;charset=utf-8
,不是我期望的 application/json
。
页面本身有我不知道如何访问的示例。
如何从此处查看实际 JSON?
您需要在 URL 中指定一个端点。 (我同意,文档不清楚。我不得不猜测 /v3
是必需的。)
所以这适用于例如:
import requests
r=requests.get("https://forgeapi.puppet.com/v3/modules") # Add /v3/modules here
print(r.status_code)
print(r.headers['content-type'])
print(r.content) # JSON data is in here
其他端点都记录在您提供的 link 中。
我正在尝试访问 Puppet Forge API 以查找最新版本的模块,以便将这些版本与我们当前的 Puppetfile 中的版本进行比较。
作为访问 APIs 的完全新手,但是,我所知道的与 Forge 文档假设我所知道的之间存在差距,所以我一无所获。
https://forgeapi.puppet.com 的文档告诉我:
The API is accessed over HTTPS via the forgeapi.puppetlabs.com domain. All data is returned in JSON format.
但是,我找不到任何 JSON 格式的数据。
我有一个简单的 Python 脚本用于连接服务器:
import requests
r=requests.get("https://forgeapi.puppet.com")
print(r.status_code)
print(r.headers['content-type'])
内容类型是 text/html;charset=utf-8
,不是我期望的 application/json
。
页面本身有我不知道如何访问的示例。
如何从此处查看实际 JSON?
您需要在 URL 中指定一个端点。 (我同意,文档不清楚。我不得不猜测 /v3
是必需的。)
所以这适用于例如:
import requests
r=requests.get("https://forgeapi.puppet.com/v3/modules") # Add /v3/modules here
print(r.status_code)
print(r.headers['content-type'])
print(r.content) # JSON data is in here
其他端点都记录在您提供的 link 中。