-3

I was trying to read data from PLC Micro Logics 1400(Allen Bradley) through Python and dump it to MS SQL, then "can only concatenate str (not "bytes") to str" this error occurred while reading data from PLC Micro Logics 1400. I will attach the python program which I am currently using. If anyone knows the solution for this kindly help me out with it.

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

Thank you!

  • 4
    Please post the code that produces this error **in the question itself**. – J... Mar 25 '21 at 11:14
  • 2
    Also, consider using the [search tool first](https://stackoverflow.com/search?q=can+only+concatenate+str+%28not+%22bytes%22%29+to+str) – J... Mar 25 '21 at 11:15

1 Answers1

0

convert bytes data into str by using decode method on the bytes object.

For example,

hello = b"Hello"
print(type(hello))
>> <class 'bytes'>

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

Then you can concatenate bytes object with str.

*("utf-8" is a type of encoding, you need to identify the type of encoding to be used to decode the byte object without error)

Ishu Kumar
  • 33
  • 7