php - 类型错误 : string indices must be integers, 不是 str - OpenErp

标签 php python integration odoo 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 集成的新手。

任何帮助将不胜感激,提前致谢!

最佳答案

您的回溯准确地告诉您需要了解的内容。

看起来您正在将字符串而不是字典传递给 _import_record。你为什么不检查一下record是。

调试正在发生的事情的最简单方法是使用 pdb Python 调试器。就在 _import_record 函数内部,ids = ... 上方把,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 调试的一般情况。如果您使用的代码不是您自己编写的,那么您将需要这项技能。

关于php - 类型错误 : string indices must be integers, 不是 str - OpenErp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20293382/

相关文章:

php - 检查用户是否存在

php - 更新后插入一条数据

python - 从源安装 lxml 时为 "IOError: [Errno ftp error] 200 Type set to I"

asp.net - 在一个Web应用程序中结合经典的ASP.NET和ASP.NET MVC

hadoop - 如何将hadoop集群与应用服务器集成?

php - 将csv文件数据插入mysql表时遇到麻烦

php - PHP 的正确 JSON 格式

Python 语法错误 : ("' return' with argument inside generator", )

python - 定义正确的requirements.txt文件

android - 如何将Facebook Connect与Android集成