相关疑难解决方法(0)

没有编码的Python字符串参数

我试图运行这段代码,并不断给出错误说"没有编码的字符串参数"

ota_packet = ota_packet.encode('utf-8') + bytearray(content[current_pos:(final_pos)]) + '\0'.encode('utf-8')
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

python encoding python-3.x python-unicode

40
推荐指数
1
解决办法
7万
查看次数

使用 Binascii 对输入进行十六进制化

我正在尝试hexlify从用户输入,但出现以下错误:

TypeError: a bytes-like object is required, not 'str'
Run Code Online (Sandbox Code Playgroud)

如果我b在字符串之前使用它,那么它可以工作,但我如何使用输入来做到这一点?
这是代码:

import binascii as bs
text = input('Please Enter Your text:')
bs.hexlify(text)
Run Code Online (Sandbox Code Playgroud)

我试着做:

text = input('Please enter you text:')
import binascii as bs
bs.hexlify(bytes(text))
Run Code Online (Sandbox Code Playgroud)

但它给出了以下错误:

TypeError: string argument without an encoding
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python python-3.x binascii

2
推荐指数
1
解决办法
3727
查看次数

标签 统计

python ×2

python-3.x ×2

binascii ×1

encoding ×1

python-unicode ×1