Skip to Content
Menu
This question has been flagged
1 Reply
4085 Views


Hi i have using tabula python library  in odoo 12 version and i got an error file not found error

df = tabula.read_pdf ((pdf)) File "/home/arun/.local/lib/python3.5/site-packages/tabula/wrapper.py", line 105, in read_pdf raise FileNotFoundError (errno.ENOENT, os .strerror (errno.ENOENT), path)

from odoo import api, models, fields, _
from odoo.exceptions import UserError, ValidationError
import logging
matter
errno import
from io import BytesIO
import tabula
_logger = logging.getLogger (__ name__)
    class ImportSalePdf (models.TransientModel):
        _name = 'import.sale.pdf'
        _description = 'Import Sale'
        file_upload_pdf = fields.Binary ('FileUpload', attachment = True)
        generate_csv = fields.Binary ('CSV File')
        def generate_pdf_csv (self):
            pdf = self.file_upload_pdf
            df = tabula.read_pdf ((pdf))
            csv = 'out.csv'
            df.to_csv (csv, sep = '\ t', encoding = 'utf-8')
            attachment_value = {
                    'name': csv.filename,
                    'datas': base64.encodestring (csv.read ()),
                    'datas_fname': csv.filename,
                    'res_model': self._name,
                    'res_id': self.id,
                }
            attachment_id = self.env ['ir.attachment']. sudo (). create (attachment_value)
\Python-3.x


Avatar
Discard
Best Answer

It's seems tabula.read_pdf required file path but you provided binary data.
convert data to file-like object using byte io (io.BytesIO)

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 24
275
0
Oct 22
1502
0
Sep 22
662
0
Jun 22
836
2
May 22
2426