我如何通过python请求输出一个特定的https请求参数?



当我收到来自discord服务器的请求时,它会发送回这样的内容:

{"message": "Unknown Gift Code", "code": 10038}

下面是我的代码:

import requests
code = str(input("Enter a code: "))
result = requests.get('https://discord.com/api/v8/entitlements/gift-codes/' + str(code) + '?with_application=true&with_subscription_plan=true')
print(result)

当我运行它时,终端给了我,这似乎是错误本身的代码,但我希望代码输出消息参数

的内容我提前为一个可能愚蠢的问题道歉。

哦,我可以自己去拿。我只是使用JSON库,这样做:

import requests
import json
code = str(input("Enter a code: "))
result = requests.get('https://discord.com/api/v8/entitlements/gift-codes/' + str(code) + '?with_application=true&with_subscription_plan=true')
f_result = json.loads(result.text)
print(f_result)

最新更新