首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnicodeEncodeError:'UCS-2‘编解码器无法对位置8-8的字符进行编码: Tk中不支持非BMP字符

UnicodeEncodeError:'UCS-2‘编解码器无法对位置8-8的字符进行编码: Tk中不支持非BMP字符
EN

Stack Overflow用户
提问于 2018-07-04 04:48:54
回答 1查看 2.9K关注 0票数 3

请记住,我今天刚开始使用Python,所以我很糟糕。

您好,我正在编写一个机器人的不一致,我遇到了一个问题,当我运行它。我正在尝试将它放到网上,但我一直收到相同的错误。我不知道错误是从哪里来的。有人能帮帮忙吗?

到目前为止,我的代码如下:

代码语言:javascript
复制
import discord

from discord.ext.commands import bot

from discord.ext import commands

import asyncio

import time

Client = discord.Client()

client = commands.Bot(command_prefix = "~")

@client.event
async def on_ready():

    print("I'm up on some BOOF!" + client.user.id)
    print("I am the" + client.user.name)

@client.event
async def on_message(message):

    if message.content == "Boof":
        await client.send_message(message.channel, ":b:")


client.run("<redacted>")

我得到的错误是:

代码语言:javascript
复制
Ignoring exception in on_ready
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/discord/client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "/Users/johnathanhelsel/Documents/Boof Bot/BoofBot.py", line 13, in on_ready
    print("I am the" + client.user.name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/run.py", line 362, in write
    return self.shell.write(s, self.tags)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/rpc.py", line 604, in __call__
    value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/rpc.py", line 216, in remotecall
    return self.asyncreturn(seq)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/rpc.py", line 247, in asyncreturn
    return self.decoderesponse(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/idlelib/rpc.py", line 267, in decoderesponse
    raise what
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 8-8: Non-BMP character not supported in Tk

我完全被卡住了!我已经尝试了所有发布的解决方案,但都没有奏效。如果可以,请帮助我!

另外,我已经修改了令牌,别再试了。

EN

回答 1

Stack Overflow用户

发布于 2018-07-04 04:54:39

您的问题是,您试图在空闲编辑器中运行代码。IDLE编辑器使用UCS-2编码,因此当您尝试打印带有奇怪的unicode字符和表情符号的用户名字符串时,IDLE窗口无法显示它。

我建议使用字符串的ascii()进行调试,这将打印unicode的python表示,而不是实际的代码点(不能打印取决于目标窗口):

代码语言:javascript
复制
print(ascii("I am the" + client.user.name))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51162636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档