コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

TypeError: a bytes-like object is required, not 'str' | Generating PDF Problem

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
python3python3.xPDFodoov11
2 返信
30046 ビュー
アバター
Ümit Öztürk

Hello, 

I upgraded my Odoo v11's python version 2.7 to 3.6. After then I fixed broken addons but I stucked that point.

Odoo showing this report in the log file:

"Generating PDF on Windows platform require DPI >= 96. Using 96 instead."

Odoo showing this report:

Traceback (most recent call last):
  File "D:\Odoo 11.0\server\odoo\http.py", line 650, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "D:\Odoo 11.0\server\odoo\http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "D:\Odoo 11.0\server\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "D:\Odoo 11.0\server\odoo\http.py", line 692, in dispatch
    result = self._call_function(**self.params)
  File "D:\Odoo 11.0\server\odoo\http.py", line 342, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "D:\Odoo 11.0\server\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "D:\Odoo 11.0\server\odoo\http.py", line 335, in checked_call
    result = self.endpoint(*a, **kw)
  File "D:\Odoo 11.0\server\odoo\http.py", line 936, in __call__
    return self.method(*args, **kw)
  File "D:\Odoo 11.0\server\odoo\http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 938, in call_button
    action = self._call_kw(model, method, args, {})
  File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 926, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "D:\Odoo 11.0\server\odoo\api.py", line 689, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "D:\Odoo 11.0\server\odoo\api.py", line 680, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "D:\Odoo 11.0\server\odoo\addons\account\models\account_invoice.py", line 780, in action_invoice_open
    return to_open_invoices.invoice_validate()
  File "D:\Odoo 11.0\server\addons\addons-trbase\l10n_tr_account_einvoice\models\account_invoice.py", line 259, in invoice_validate
    [inv.id], 'account.report_invoice', {})
  File "D:\Odoo 11.0\server\addons\addons-trbase\report_router\models\ir_actions_report.py", line 77, in render_report
    res_ids, route.report_id.report_name, data)
  File "D:\Odoo 11.0\server\addons\addons-trbase\report_router\models\ir_actions_report.py", line 61, in render_report
    res_ids, name, data)
  File "D:\Odoo 11.0\server\addons\addons-trbase\report_xslt\models\ir_actions_report_xml.py", line 48, in render_report
    return self.create_xslt_report(report, res_ids, data)
  File "D:\Odoo 11.0\server\addons\addons-trbase\report_xslt\models\ir_actions_report_xml.py", line 147, in create_xslt_report
    pdf = self._run_wkhtmltopdf(htmls)
  File "D:\Odoo 11.0\server\odoo\addons\base\ir\ir_actions_report.py", line 378, in _run_wkhtmltopdf
    body_file.write(body)
TypeError: a bytes-like object is required, not 'str'

When I want to send e-invoice, it's sending but it couldn't create PDF file of that e-invoice and giving error for this. 


Environment Informations: 

Odoo v11
Python 3.6
an invoice provider (localized)


Here is create_xslt_report function:

    def create_xslt_report(self, report, res_ids, data=None):
        if data is None:
            data = {}
        resources = self.env[report.model].browse(
            res_ids)
        htmls = []
        for resource in resources:
            xslt = data.get('xslt', False)
            if xslt:
                xslt = etree.fromstring(xslt)
            else:
                xslt = etree.fromstring(base64.decodebytes(report.xslt))
            transform = etree.XSLT(xslt)
            res_xml = data.get('xml', False)
            if res_xml:
                parser = etree.XMLParser(recover=True)
                res_etree = etree.fromstring(res_xml, parser)
            else:
                if getattr(resource, '_get_xml_etree', None):
                    res_etree = resource._get_xml_etree()
                    res_xml = etree.tostring(res_etree, encoding='utf8',
                                             method='xml', pretty_print=False)
                elif getattr(resource, '_get_xml_string', None):
                    parser = etree.XMLParser(recover=True)
                    res_xml = resource._get_xml_string()
                    res_etree = etree.fromstring(res_xml, parser)
                else:
                    raise ValidationError(_(
                        'This model does not support XSLT reports'))
            htmls.append(str(transform(res_etree)))
        if data.get('return_htmls', False):
            return htmls
        # pdf = self._run_wkhtmltopdf([], [], htmls, None, paperformat,
        #                             {}, save_in_attachment)
        pdf = self._run_wkhtmltopdf(htmls)
        save_in_attachment, res_ids = self.xslt_get_attachment(report, res_ids)
        reportResult = report.with_context({})._post_pdf(save_in_attachment, pdf, res_ids)
        save_in_attachment, res_ids = self.xslt_get_attachment(report, res_ids)
        # save_in_attachments has always data in odoo v8
        # in v11, it has data only when we already have attachment
        if report.attach_xml and len(resources) == 1:
            resource_id = resource[0].id
            filename = save_in_attachment.get(resource_id)
            filename = filename and filename.datas_fname or ''
            if filename:
                xml_filename = os.path.splitext(filename)[0] + '.xml'
                pdf = self.attach_file_to_pdf(pdf, res_xml, xml_filename)
                att = self.env['ir.attachment'].search(
                    [('res_model', '=', report.model),
                     ('res_id', '=', resource_id),
                     ('datas_fname', '=', filename), ], limit=1)
                if att:
                    att.write({
                        'datas': base64.b64encode(pdf),
                    })
                else:
                    self.env['ir.attachment'].with_context({}).create({
                        'res_model': report.model,
                        'res_id': resource_id,
                        'name': filename,
                        'datas_fname': filename,
                        'datas': base64.b64encode(pdf),
                    })
        return pdf, 'pdf'

By the way these codes are working with python 2.7. I only changed decodebytes() instead of decodestring()


I hope, you'll find way to solve this problem. 

0
アバター
破棄
Ümit Öztürk
著作者

yes, i solved the problem. The main error is base64 encode-decode relations. That's the reason why it's giving error. Check your decode method.

アバター
ronaldgevern
最善の回答

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes instead. We can convert bytes to string using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is "utf-8" , so you can use directly:

b"python byte to string".decode("utf-8")

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.

http://net-informations.com/python/iq/byte.htm

0
アバター
破棄
アバター
Kirubanidhi Rajarathinam
最善の回答

Did u solved your problem. Please give me the idea. I am also facing this problem. While create new record..

Odoo Server Error

Traceback (most recent call last):

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 653, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 312, in _handle_exception

raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

File "/opt/odoo/12.0-LS/12.0/odoo/tools/pycompat.py", line 87, in reraise

raise value

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 695, in dispatch

result = self._call_function(**self.params)

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 344, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/opt/odoo/12.0-LS/12.0/odoo/service/model.py", line 97, in wrapper

return f(dbname, *args, **kwargs)

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 337, in checked_call

result = self.endpoint(*a, **kw)

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 938, in __call__

return self.method(*args, **kw)

File "/opt/odoo/12.0-LS/12.0/odoo/http.py", line 517, in response_wrap

response = f(*args, **kw)

File "/opt/odoo/12.0-LS/12.0/addons/web/controllers/main.py", line 966, in call_button

action = self._call_kw(model, method, args, {})

File "/opt/odoo/12.0-LS/12.0/addons/web/controllers/main.py", line 954, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 749, in call_kw

return _call_kw_multi(method, model, args, kwargs)

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 736, in _call_kw_multi

result = method(recs, *args, **kwargs)

File "/opt/odoo/12.0-LS/lab_society/lab_society/woo_commerce_v10/wizard/woo_process_import_export.py", line 78, in execute

self.import_sale_orders()

File "/opt/odoo/12.0-LS/lab_society/lab_society/woo_commerce_v10/wizard/woo_process_import_export.py", line 306, in import_sale_orders

sale_order_obj.import_new_woo_orders(instance)

File "/opt/odoo/12.0-LS/lab_society/lab_society/woo_commerce_v10/models/sale_order.py", line 875, in import_new_woo_orders

partner=order.get('billing',False) and self.create_or_update_woo_customer(woo_customer_id,order.get('billing'), False, False,False,instance)

File "/opt/odoo/12.0-LS/lab_society/lab_society/woo_commerce_v10/models/sale_order.py", line 120, in create_or_update_woo_customer

'property_payment_term_id':instance.payment_term_id and instance.payment_term_id.id or False,

File "<decorator-gen-122>", line 2, in create

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 451, in _model_create_multi

return create(self, [arg])

File "/opt/odoo/12.0-LS/12.0/addons/partner_autocomplete/models/res_partner.py", line 166, in create

partners = super(ResPartner, self).create(vals_list)

File "<decorator-gen-84>", line 2, in create

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 452, in _model_create_multi

return create(self, arg)

File "/opt/odoo/12.0-LS/12.0/odoo/addons/base/models/res_partner.py", line 553, in create

partners = super(Partner, self).create(vals_list)

File "<decorator-gen-112>", line 2, in create

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 452, in _model_create_multi

return create(self, arg)

File "/opt/odoo/12.0-LS/12.0/addons/mail/models/mail_thread.py", line 272, in create

threads = super(MailThread, self).create(vals_list)

File "<decorator-gen-3>", line 2, in create

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 452, in _model_create_multi

return create(self, arg)

File "/opt/odoo/12.0-LS/12.0/odoo/models.py", line 3504, in create

records = self._create(data_list)

File "/opt/odoo/12.0-LS/12.0/odoo/models.py", line 3628, in _create

for other, data in pycompat.izip(others, data_list)

File "/opt/odoo/12.0-LS/12.0/odoo/fields.py", line 1816, in create

for record, value in record_values

File "<decorator-gen-41>", line 2, in create

File "/opt/odoo/12.0-LS/12.0/odoo/api.py", line 452, in _model_create_multi

return create(self, arg)

File "/opt/odoo/12.0-LS/12.0/odoo/addons/base/models/ir_attachment.py", line 495, in create

values = self._check_contents(values)

File "/opt/odoo/12.0-LS/12.0/odoo/addons/base/models/ir_attachment.py", line 256, in _check_contents

xml_like = 'ht' in mimetype or 'xml' in mimetype # hta, html, xhtml, etc.

TypeError: a bytes-like object is required, not 'str'

0
アバター
破棄
Kirubanidhi Rajarathinam

I will try your answer. thanks for giving me your suggestion

ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Why index error: list out of range is coming ? 解決済
python python3 python3.x odoo11 odoov11
アバター
アバター
1
12月 19
4314
How to solve this InvalidDatetimeFormat error in Odoo 11
python python3 python3.x odoo11 odoov11
アバター
0
8月 19
4328
Database restore error : “There is no item named 'dump.sql' in the archive”
postgresql python3.x odoo.sh odoov11
アバター
0
3月 22
11935
How to programmatically convert ir.attachment into a pdf file in odoo15?
ir.attachment python3 PDF v15
アバター
アバター
1
11月 21
6446
Module not install properly. 解決済
yml python3 odoo odoov11
アバター
アバター
アバター
アバター
7
9月 19
8442
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now