3

I am trying to hexlify input from user but I get the following error:

TypeError: a bytes-like object is required, not 'str'

If I use b before string then it works but how can I do it with input?
Here is the code:

import binascii as bs
text = input('Please Enter Your text:')
bs.hexlify(text)

I tried doing:

text = input('Please enter you text:')
import binascii as bs
bs.hexlify(bytes(text))

But it gives the following error:

TypeError: string argument without an encoding

How can I do that?

Nouman
  • 6,947
  • 7
  • 32
  • 60

1 Answers1

5

Add encoding parameter to bytes:

import binascii as bs
text = input('Please Enter Your text:')
bs.hexlify(bytes(text, encoding="utf8"))
Dor-Ron
  • 1,787
  • 3
  • 15
  • 27