user3907104
user3907104

Reputation: 1

f.write (data) TypeError: a bytes-like object is required, not 'str'

enter image description here

if i change data = data + payload to data = data + str(payload)

I will then have this error
f.write (data) TypeError: a bytes-like object is required, not 'str'

So what can I do to change the code to let the script run

Upvotes: 0

Views: 1383

Answers (2)

Daweo
Daweo

Reputation: 36735

You need to open file in appriopiate mode, default is text mode where str should be provided for writing, whilst b denotes binary mode where bytes is expected, consider following simple examples:

with open("file1.txt","w") as f:
    f.write("HELLO")
with open("file2.txt","wb") as f:
    f.write(b"\x48\x45\x4C\x4C\x4F")

Upvotes: 1

danangjoyoo
danangjoyoo

Reputation: 360

Try to convert it first. data = data.encode()

Upvotes: 1

Related Questions