need long found dict coercing python api unicode buffer typeerror

python - long - TypeError: coercing to Unicode: necesita cadena o búfer, se encontró int



typeerror coercing to unicode need string or buffer dict found (2)

El problema podría tener que ver con el hecho de que está agregando entradas a las cadenas aquí

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

Que yo sepa, el intérprete no puede convertir implícitamente un int en una cadena. Esto podría funcionar, sin embargo,

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

En el que estoy asumiendo Python> 3.0

Tengo 2 APIs. Estoy buscando datos de ellos. Quiero asignar partes de código particulares a la cadena para que la vida sea más fácil mientras se codifica. Aquí está el código:

import urllib2 import json urlIncomeStatement = ''http://dev.c0l.in:8888'' apiIncomeStatement = urllib2.urlopen(urlIncomeStatement) dataIncomeStatement = json.load(apiIncomeStatement) urlFinancialPosition = ''http://dev.c0l.in:9999'' apiFinancialPosition = urllib2.urlopen(urlFinancialPosition) dataFinancialPositiont = json.load(apiFinancialPosition) for item in dataIncomeStatement: name = item[''company''][''name''] interestPayable = int(item[''company''][''interest_payable'']) interestReceivable = int(item[''company''][''interest_receivable'']) sales = int(item[''company''][''interest_receivable'']) expenses = int(item[''company''][''expenses'']) openingStock = int(item[''company''][''opening_stock'']) closingStock = int(item[''company''][''closing_stock'']) sum1 = sales + expenses 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 print sum1

Como resultado obtengo:

Traceback (most recent call last): File "C:/Users/gnite_000/Desktop/test.py", line 25, in <module> name + "''s interest payable - " + interestPayable TypeError: coercing to Unicode: need string or buffer, int found


Tienes que agregar ''% s''% y () a cada línea, como esto:

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