TypeError: coercing to Unicode: need string or buffer, int found TypeError: coercing to Unicode: need string or buffer, int found python python

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


The problem might have to do with the fact that you are adding ints to strings here

    if item['sector'] == 'technology':        name + "'s interest payable - " + interestPayable        name + "'s interest receivable - " + interestReceivable        name + "'s interest receivable - " + sales        name + "'s interest receivable - " + expenses        name + "'s interest receivable - " + openingStock        name + "'s interest receivable - " + closingStock

As far as I'm aware, the interpretor cannot implicitly convert an int to a string.This might work, though,

       str(name) + "'s interest receivable - " + str(closingStock)

On which I'm assuming Python > 3.0


You have to add '%s' % and () to each line, like this:

'%s' % (name + "'s interest payable - " + interestPayable)