Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python TypeError: coercing to Unicode: need string or buffer, tuple found

#!/usr/bin/env python
import sys
import os

print "Scan a file for ""ErrorScatter"" payload"
print "Drag the suspicious file here then press enter."
filepath = raw_input("File Location: ")
fixpath = filepath , "/Contents/MacOS/ErrorScatter"
scan = os.path.exists(fixpath)

So i am making a program to check if a file has a "ErrorScatter" payload but i keep coming across and error when testing my creation. Since i'm a newb i do not know how to fix this.

This is the error i'm getting:

TypeError: coercing to Unicode: need string or buffer, tuple found

Would anyone know how to fix this?

like image 665
ACiDRAiN Avatar asked Mar 03 '15 07:03

ACiDRAiN


1 Answers

, operator in Python is used to create tuples, for example

1, 2, 3

makes 3-element tuple

(1, 2, 3)

and

"blah", "bleh"

means 2-element tuple

("blah", "bleh")

To concatenate strings, you could use + as Gaurav already suggested:

fixpath = filepath + "/Contents/MacOS/ErrorScatter"

but in fact the better way is to

import os

fixpath = os.path.join(filepath, "Contents/MacOS/ErrorScatter")

or even

fixpath = os.path.join(filepath, "Contents", "MacOS", "ErrorScatter")

(using os.path.join is a habit you will appreciate once you happen to run some scripts on windows, this one is not too likely but habits grow by repetition...)

like image 145
Mekk Avatar answered Sep 17 '22 00:09

Mekk