"can only concatenate str (not "字节") to str" Python 到 PLC 连接



我试图通过Python从PLC Micro Logics 1400(Allen Bradley(读取数据,并将其转储到MS SQL,然后"只能将str(而不是"字节"(连接到str">从PLC Micro Logics 1400读取数据时发生此错误。我将附加我目前正在使用的python程序。如果有人知道这个问题的解决方案,请帮助我。

https://drive.google.com/file/d/1C-g4M5YhtsvvTCaDnz3jLhYuRg64E-8f/view?usp=sharing

谢谢!

bytes对象上使用decode方法将bytes数据转换为str

例如,

hello = b"Hello"
print(type(hello))
>> <class 'bytes'>
hello.decode("utf-8")
print(type(hello))
>> <class 'str'>

然后可以将bytes对象与str连接起来。

*("utf-8"是一种编码类型,您需要确定用于无错误解码字节对象的编码类型(

最新更新