首页 > 解决方案 > Python,TypeError:没有编码的字符串参数

问题描述

我需要一些帮助。由于某种原因,它一直显示 typeError:string 参数而没有编码,

sent_message = network_connect_join.send(bytes(sending_message)).encode('utf-8')

它的代码片段,下一行只是打印出正常的消息

标签: python-3.xencoding

解决方案


bytes()处理字符串时需要两个参数:要转换为字节的字符串和要使用的编码。改为使用bytes(sending_message, 'utf-8')


推荐阅读