TypeError:字符串索引必须是整数,而不是str - OpenErp

时间:2013-11-29 21:08:12

标签: php python integration openerp prestashop

我正在使用prestashop - openerp连接器模块,但是当我尝试从网站导入数据时,会给我这个错误追溯:

  File "/usr/prestaconnect/openerp-connector/connector/queue/worker.py", line 122, in run_job
job.perform(session)
  File "/usr/prestaconnect/openerp-connector/connector/queue/job.py", line 460, in perform
self.result = self.func(session, *self.args, **self.kwargs)
  File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 663, in import_batch
importer.run(filters=filters, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 202, in run
return super(PaymentMethodsImportSynchronizer, self).run(filters, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 176, in run
record_ids = self._run_page(filters)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 186, in _run_page
self._import_record(record_id, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 206, in _import_record
('name', '=', record['payment']),
TypeError: string indices must be integers, not str

在模块代码中我看到了:

 class PaymentMethodsImportSynchronizer(BatchImportSynchronizer):
_model_name = 'payment.method'

def run(self, filters=None, **kwargs):
    if filters is None:
        filters = {}
    filters['display'] = '[id,payment]'
    return super(PaymentMethodsImportSynchronizer, self).run(filters, **kwargs)

def _import_record(self, record):
    ids = self.session.search('payment.method', [
        ('name', '=', record['payment']),
        ('company_id', '=', self.backend_record.company_id.id),
    ])
    if ids:
        return
    self.session.create('payment.method', {
        'name': record['payment'],
        'company_id': self.backend_record.company_id.id,
    })

我不知道实际发生了什么,我需要一些亮点,因为我没有开发这个模块,而且我是prestashop-openerp集成的新手。

非常感谢任何帮助,提前谢谢!

1 个答案:

答案 0 :(得分:1)

您的追溯会告诉您确切需要了解的内容。

看起来你正在将字符串传递给_import_record而不是dict。你为什么不查看record是什么。

调试正在发生的事情的最简单方法是使用pdb Python调试器。就在_import_record函数内部,在ids = ... put,import pdb; pdb.set_trace()之上。然后像往常一样运行程序,pdb将在该行中断,然后您可以分析record设置的内容。

请参阅:http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/Getting started with the Python Debugger pdb一般的pdb介绍和Python调试。如果您正在使用自己未编写的代码,则需要此技能。