简体   繁体   English

有人可以告诉我这段代码有什么问题吗

[英]Can someone please tell me whats wrong with this code

response = get(url='https://benbotfn.tk/api/v1/aes')
 
data = response.json()
 
 
@client.command()
async def aes123(ctx):
  await ctx.send(data['mainKey'])
 
 
@client.command()
async def aeskey(ctx):
 embed=discord.Embed(title="aes")
 embed.add_field(name='aes', value=f'{data['mainKey']} aes key')
 


 await ctx.send(embed=embed)

I am getting this error when I run this code:运行此代码时出现此错误:

参考

I really don't know what's wrong with this code and I'm just starting out, so sorry if this is a dumb question!我真的不知道这段代码有什么问题,我才刚刚开始,如果这是一个愚蠢的问题,很抱歉!

Inside f'' strings, if you need to access something using another string, its best to use the other quote type.f''字符串中,如果您需要使用另一个字符串访问某些内容,最好使用其他引号类型。

In this case:在这种情况下:

value=f'{data['mainKey']} aes key'

is invalid syntax since you have sets of quotes within a string literal.是无效的语法,因为您在字符串文字中有多组引号。 The correct way to do it in this case is:在这种情况下,正确的做法是:

value=f'{data["mainKey"]} aes key'

Note the use of double quotes.注意使用双引号。 Alternative options include:替代选项包括:

value=f"{data['mainKey']} aes key"

value=f'''{data['mainKey']} aes key'''

value=f"""{data["mainKey"]} aes key"""

All of these options are valid and have their uses.所有这些选项都是有效的并且有它们的用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我此代码针对基于心情发出qoutes的函数有什么问题吗? - can someone tell me whats wrong with this code for a function that gives out qoutes based on mood? 有人可以告诉我这个 python 代码哪里错了吗? - Can someone please tell me where am I wrong in this python code? python,请告诉我出了什么问题 - python, please tell me whats wrong arg不能被强制转换为java.util.List吗? 有人可以告诉我我的代码有什么问题吗? - arg can't be coerced to java.util.List? Could any one tell me whats wrong in my code please? 有人可以告诉我合并排序的代码有什么问题吗? - Can some tell me whats wrong with my code for merge sort? 你能告诉我这有什么问题吗 - Can you please tell whats wrong with this 我不明白为什么这段代码不起作用! 有人可以告诉我我做错了吗? - I don't see why this code is not working! can someone please tell me what i am doing wrong? 有人能告诉我我的代码有什么问题吗 - Can someone tell me what is wrong with my code 有人可以告诉我我的 animation 代码有什么问题吗? - Can someone tell me what's wrong with my animation code? 告诉我这个python代码有什么问题吗? - Tell me whats wrong with this python code?
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM