Ryan
Ryan

Reputation: 1095

Python TypeError unsupported operand type(s) for %: 'file' and 'unicode'

I'm working on a django field validation and I can't figure out why I'm getting a type error for this section:

def clean_tid(self):
    data = self.cleaned_data['tid']
    stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN")  % data
    result = stdout_handel.read()

Do I have to convert data somehow before I can pass it in as a string variable?

Upvotes: 0

Views: 2673

Answers (2)

gavoja
gavoja

Reputation: 377

Just a small tip - it's better to use subprocess module and Popen class instead of os.popen function. More details here (docs).

Upvotes: 1

S.Lott
S.Lott

Reputation: 391828

Check your parenthesis.

Wrong

stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN")  % data

Might be right.

stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN"  % data )

Upvotes: 1

Related Questions