Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hexlify input using Binascii [duplicate]

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?

like image 599
Black Thunder Avatar asked Mar 03 '26 16:03

Black Thunder


1 Answers

Add encoding parameter to bytes:

import binascii as bs
text = input('Please Enter Your text:')
bs.hexlify(bytes(text, encoding="utf8"))
like image 184
Dor-Ron Avatar answered Mar 05 '26 05:03

Dor-Ron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!