这是我正在尝试的apihttps://api.apithis.net/host2ip.php?hostname=google.com 正如您所看到的,与json API不同,它没有可以复制为response.json的“”
@client.command()
async def host(ctx, host):
url = ('https://api.apithis.net/host2ip.php?hostname=' + host)
response = requests.get(url)
ipaddress = response.json()
embed = discord.Embed(title="IP for website" + host, color=0x00ffff)
embed.add_field(name="IP:", value=f'{ipaddress}', inline=True)
await ctx.send(embed=embed)
这是我目前的代码,如果有人可以修复,这会有很大帮助,因为我不知道如何在没有json输出的情况下使用API,谢谢
首先,您得到的响应不是JSON。如果您看到
response header
,那么您可以看到它是content-type: text/html; charset=UTF-8
既然它不是JSON,就必须将其视为文本
您可以简单地使用
Response.text
属性相关问题 更多 >
编程相关推荐