API错误:TypeError:字符串索引必须是整数

发布于 2025-02-12 17:08:57 字数 866 浏览 0 评论 0原文

我真的是Stackoverflow的新手。

我想创建一个 pterodactyl 使用Python的客户端面板。但是,如果我想在面板上获取服务器信息,它将向我展示:

Traceback (most recent call last):
  File "system_server.py", line 16, in <module>
    print(resp['data'])
TypeError: string indices must be integers  

我的代码:

import json
import requests
import configuration
url = 'https://client.blutudlut.xyz/api/application/servers'
headers = {
    "Authorization": "Bearer "+ configuration.pterodactyl_admin_api,
    "Accept": "application/json",
    "Content-Type": "application/json",
}

response = requests.request('GET', url, headers=headers)
print(response.text)
json_str = json.dumps(response.text)
resp = json.loads(json_str)
print(resp)
print(resp['data'])

我尝试了多种方法,但始终是同一问题。

I'm really new to StackOverflow.

I want to create a Pterodactyl Client Panel using Python. But if I want to get the servers Info on the Panel it shows me this:

Traceback (most recent call last):
  File "system_server.py", line 16, in <module>
    print(resp['data'])
TypeError: string indices must be integers  

My Code:

import json
import requests
import configuration
url = 'https://client.blutudlut.xyz/api/application/servers'
headers = {
    "Authorization": "Bearer "+ configuration.pterodactyl_admin_api,
    "Accept": "application/json",
    "Content-Type": "application/json",
}

response = requests.request('GET', url, headers=headers)
print(response.text)
json_str = json.dumps(response.text)
resp = json.loads(json_str)
print(resp)
print(resp['data'])

I tried many ways but it's always the same problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文