【问题标题】:"can only concatenate str (not "bytes") to str" Python to PLC Connection“只能将 str(不是“字节”)连接到 str” Python 到 PLC 连接
【发布时间】:2021-06-22 04:22:54
【问题描述】:

我试图通过 Python 从 PLC Micro Logics 1400(Allen Bradley) 读取数据并将其转储到 MS SQL,然后 "can only concatenate str (not "bytes") to str" this从 PLC Micro Logics 1400 读取数据时发生错误。我将附上我当前使用的 python 程序。如果有人知道这个问题的解决方案,请帮助我。

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

谢谢!

【问题讨论】:

  • 在问题本身中发布产生此错误的代码。
  • 另外,考虑使用search tool first

标签: python concatenation plc


【解决方案1】:

通过对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"是一种编码类型,需要识别出用于解码字节对象的编码类型不出错)

【讨论】:

    猜你喜欢
    • 2021-11-07
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 2021-02-22
    • 2020-09-18
    相关资源
    最近更新 更多