Ошибка в Python/C - TypeError: an integer is required (got type dict)
Запускаю код, возникает ошибка -
TypeError: an integer is required (got type dict)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <built-in function test> returned a result with an error set
Код:
PyObject *list;
if (!PyArg_ParseTuple(args, "O", &list)) {
return NULL;
}
int b = 0;
if (list != NULL) {
PyObject *iter = PyObject_GetIter(list);
while (1) {
PyObject *next = PyIter_Next(iter);
if (next == NULL)
break;
if (PyDict_Check(next)) {
PyObject *p = PyDict_GetItemString(next, "text");
if (p != NULL) {
if (PyLong_Check(p)) {
b += PyLong_AsLong(next);
}
}
}
}
}
return Py_BuildValue("i", b);