首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误: save()获得意外的关键字参数'format‘

错误: save()获得意外的关键字参数'format‘
EN

Stack Overflow用户
提问于 2018-06-26 22:37:33
回答 1查看 900关注 0票数 0

我正在使用Odoo9,我正在尝试安装名为odoo_qr_code的自定义模块,它允许在产品表单中添加二维码,并为产品和产品变体创建qr图像。但是当我在产品表单中添加我的二维码后按下保存时,它显示错误。有什么需要帮忙的吗?

代码语言:javascript
复制
File "D:\Projet_Odoo\odoo-9.0rc20180515\openerp\addons\odoo_qr_code\models\models.py", line 23, in _generate_qr_code
img.save(buffer, format="PNG")
TypeError: save() got an unexpected keyword argument 'format'

models.py

代码语言:javascript
复制
import base64
import cStringIO

import qrcode
from openerp import models, fields, api


class ProductTemplateQRCode(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('product_qr_code')
def _generate_qr_code(self):
    qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=4)
    if self.product_qr_code:
        name = self.product_qr_code + '_product.png'
        qr.add_data(self.product_qr_code)
        qr.make(fit=True)
        img = qr.make_image()
        buffer = cStringIO.StringIO()
        img.save(buffer, format="PNG")
        qrcode_img = base64.b64encode(buffer.getvalue())
        self.update({'qr_code': qrcode_img, 'qr_code_name': name})

product_qr_code = fields.Char('QR Code')
qr_code = fields.Binary('QR Code', compute="_generate_qr_code")
qr_code_name = fields.Char(default="qr_code.png")


class ProductProductQRCode(models.Model):
_inherit = 'product.product'

@api.multi
@api.depends('product_qr_code')
def _generate_qr_code(self):
    qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=4)
    if self.product_qr_code:
        name = self.product_qr_code + '_product.png'
        qr.add_data(self.product_qr_code)
        qr.make(fit=True)
        img = qr.make_image()
        buffer = cStringIO.StringIO()
        img.save(buffer, format="PNG")
        qrcode_img = base64.b64encode(buffer.getvalue())
        self.update({'qr_code': qrcode_img, 'qr_code_name': name})
EN

回答 1

Stack Overflow用户

发布于 2018-06-27 21:31:25

该错误指出函数save不接受参数format。因此,您需要(从两个函数中)删除它。

您可以参考how to create QR code in python的此this链接。

希望能对你有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51045547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档