0

I have this code:

cmd_login =   '534d4100000402a000000001003a001060650ea0ffffffffffff00017800%s00010000000004800c04fdff07000000840300004c20cb5100000000%s00000000' % (struct.pack('<I', src_serial).encode('hex'), get_encoded_pw(user_pw))

written for python 2.7.

I don't find how to change this, to get it working in python 3.9. I get the error: 'bytes' object has no attribute 'encode'.

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
WannesNaf
  • 9
  • 1

1 Answers1

0

The struct.pack function returns a bytes object. If you want to convert that to a hex string it has direct support for that using its hex() method.

data = b"abcde"
data.hex()

Produces:

'6162636465'
Keith
  • 40,128
  • 10
  • 53
  • 74