Python 尝试使用hashes.org api生成散列破解命令时,error命令引发异常:KeyError:';结果';
我的代码如下:Python 尝试使用hashes.org api生成散列破解命令时,error命令引发异常:KeyError:';结果';,python,discord,discord.py,Python,Discord,Discord.py,我的代码如下: @commands.command(name='crackhash', aliases = ['hashcrack']) async def hashcracking(self, ctx, query): url = "https://hashes.org/api.php?key=" + hashapi_key + ".&query=" + query async with Clien
@commands.command(name='crackhash', aliases = ['hashcrack'])
async def hashcracking(self, ctx, query):
url = "https://hashes.org/api.php?key=" + hashapi_key + ".&query=" + query
async with ClientSession() as session:
async with session.get(url) as response:
r = await response.json(content_type=None)
embed = discord.Embed(colour=discord.Colour.purple(), timestamp=ctx.message.created_at,
title=f"Hash Cracking")
member = ctx.message.author
embed.set_thumbnail(url=member.avatar_url)
embed.set_footer(text=f"Requested by {ctx.author}")
embed.add_field(name=f"Status", value={r['status']}, inline=False)
embed.add_field(name=f"{query}", value="Algorithm: " + [r][0]['result'][query]['algoritm]'], inline=False)
embed.add_field(name=f"Plaintext", value={r[0]['result'][query]['plain']}, inline=False)
await ctx.send(embed=embed)
下面是API的一个示例:
如果有人能帮上忙那就太好了,因为老实说,我不知道我在做什么-
embed.add_field(name=f"{query}", value="Algorithm: " + [r['result'][query]['algorithm'], inline=False)
embed.add_field(name=f"Plaintext", value={r['result'][query]['plain']}, inline=False)
修正了我自己的代码。
将其更改为:
@commands.command(name='crackhash', aliases = ['hashcrack'])
async def hashcracking(self, ctx, query):
url = "https://hashes.org/api.php?key=" + hashapi_key + "&query=" + query
async with ClientSession() as session:
async with session.get(url) as response:
str(query)
r = await response.json(content_type=None)
embed = discord.Embed(colour=discord.Colour.purple(), timestamp=ctx.message.created_at,
title=f"Hash Cracking")
status = (f"{r['status']}")
status.capitalize()
member = ctx.message.author
embed.set_thumbnail(url=member.avatar_url)
embed.set_footer(text=f"Requested by {ctx.author}")
embed.add_field(name=f"Status", value=status, inline=False)
embed.add_field(name=f"Algorithm", value=f"{r['result'][query]['algorithm']}", inline=False)
embed.add_field(name=f"Plaintext", value=f"{r['result'][query]['plain']}", inline=False)
await ctx.send(embed=embed)
谢谢你的帮助 也许如果查询失败(即
“status”
不是“success”
),那么就没有“result”
字段?打印r
将是一个好的开始。给我这个错误:discord.ext.commands.errors.CommandInvokeError:Command引发了一个异常:KeyError:“algorithm”