This question has been flagged
2 Replies
9810 Views

OpenERP application sale_report_html encounters the following error on my Ubuntu 12.10, OpenERP 6.1 and Mako 0.7.1-1 system.

Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0

(<class 'mako.exceptions.compileexception'="">, CompileException("Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0",), <traceback object="" at="" 0xb43e9bbc="">)

and the /var/log/openerp-server.log

2013-03-05 23:34:32,129 18019 ERROR ? openerp.service.web_services: Exception: Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 727, in go
    (result, format) = obj.create(cr, uid, ids, datas, context)
  File "/usr/lib/pymodules/python2.7/openerp/report/report_sxw.py", line 442, in create
    fnct_ret = fnct(cr, uid, ids, data, report_xml, context)
  File "/usr/lib/pymodules/python2.7/openerp/report/report_sxw.py", line 454, in create_source_mako2html
    return self.create_single_mako2html(cr, uid, ids, data, report_xml, context or {})
  File "/usr/lib/pymodules/python2.7/openerp/report/report_sxw.py", line 677, in create_single_mako2html
    html = create_doc(mako_html,html_parser.localcontext)
  File "/usr/lib/pymodules/python2.7/openerp/report/interface.py", line 243, in create_makohtml2html
    obj.render()
  File "/usr/lib/pymodules/python2.7/openerp/report/render/render.py", line 59, in render
    self._result = self._render()
  File "/usr/lib/pymodules/python2.7/openerp/report/render/rml.py", line 91, in _render
    return makohtml.parseNode(self.html,self.localcontext)
  File "/usr/lib/pymodules/python2.7/openerp/report/render/makohtml2html/makohtml2html.py", line 135, in parseNode
    return r.render()
  File "/usr/lib/pymodules/python2.7/openerp/report/render/makohtml2html/makohtml2html.py", line 119, in render
    template = Template(self.html, lookup=temp_lookup)
  File "/usr/lib/python2.7/dist-packages/mako/template.py", line 206, in __init__
    (code, module) = _compile_text(self, text, filename)
  File "/usr/lib/python2.7/dist-packages/mako/template.py", line 484, in _compile_text
    node = lexer.parse()
  File "/usr/lib/python2.7/dist-packages/mako/lexer.py", line 192, in parse
    self.filename,)
  File "/usr/lib/python2.7/dist-packages/mako/lexer.py", line 184, in decode_raw_stream
    0, 0, filename)
CompileException: Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0
2013-03-05 23:34:32,358 18019 ERROR ? openerp.netsvc: Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0
(<class 'mako.exceptions.compileexception'="">, CompileException("Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0",), <traceback object="" at="" 0xb8071e4="">)

I've made no changes to sale_report_html other than "mv __terp__.py __openerp__.py" which I was told is required.

One suggestion I'd encountered said that I should change all the string references in sale_order_html.mako from ${ 'this is some string' } to ${ u'this is some string' }. And I'm willing to do that, but; most of the string references are of the form ${ o.partner_id.title or '' } and I'm unsure how to convert that to unicode.

What do you suggest?

Avatar
Discard
Author

Making the template file (sale_report_html.mako) line one = "## -- encoding: utf-8 --" is not the solution I had hoped for.

I updated my answer. For the third error, try to comment line mako header xor footer. Bye

Best Answer

Hi,

install good mako library version with command :

pip install Mako==0.2.4

in file sale_report_html/report/sale_order_html.mako, at the first line add line :

# -*- coding: utf-8 -*-

save the file.

restart openerp server

update the module

this solve the error you gave (tested)

now you will have an other error, to solve it do :

go to settings/parameter setting/low level/actions/reports

search report with name "Order(HTML using Mako)"

open the line and edit field "type" with "mako2html"

save

restart openerp server

update the module

solve the second error (tested).

but now a third error comes.

then to you to search how to solve it

Bye

Avatar
Discard
Author

I've trimmed sale_order_html.mako down to just the html, header and body tags with nothing except for BODY in in the body. I changed "## -- coding: utf-8 --" to "## -- coding: ascii --" in sale_order_html.mako, mako_header.html and mako_footer.html. I get the same error.

Author

I changed "## -- coding: ascii --" to "## -- coding: utf-8 --" in sale_order_html.mako, mako_header.html and mako_footer.html. I get the same error.

Author

sale_order_html.py has almost nothing in it so I've made no changes there.

Hi, ## -- coding: utf-8 -- in the head is just for the text in the document file, to be interperted correctly in variable you should use attribute .decode as I said : ${ (o.partner_id.title).decode('utf-8') or '' } .Did you try, this not works ??? Did you read documentation link ???? Bye

Author

I pulled all the fields out of the .mako thinking that would accomplish the same thing (no fields, no .decode() needed.) I'd like for ANYTHING to work with mako2html, but; so far none of the examples, nor anything I program works. Even the most minimal case.

did you restart openerp server and update module ? What is log error message (the last 10 lines)

Author

I did; "service openerp restart" has become my fastest typed phrase.

Author

2013-03-07 16:43:40,538 14090 ERROR ? openerp.service.web_services: Exception: Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0 Traceback (most recent call last): File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 763, in go (result, format) = obj.create(cr, uid, ids, datas, context) File "/usr/lib/pymodules/python2.7/openerp/report/report_sxw.py", line 442, in create fnct_ret = fnct(cr, uid, ids, data, report_xml, context) File "/usr/lib/pymodules/python2.7/openerp/report/report_sxw.py", line 454, in create_source_mako2

Author

Too bad wraping <pre></pre> around that last comment doesn't get it to look correct. But, it's the same as the error in my OP (only poorly formatted, and the last bunch is truncated.)

I updated my original answer, good luck for the third error, perhaps try to verify with mako version 0.2.4. Bye

I reupdated my answer because line to add in th head of file mako was not displayed correctly. Bye

Author

Thanks for all your time and effort @GEM. Does it work OK for you? If so would you tell me what versions you are using? I encounter errors left and right with Mako 0.7.1-1 so finally downgraded to 0.2.4. Where the "## -- coding: utf-8 --" resolves the encoding complaints. But other errors crop up.

Author

'Fragment 'include file="mako_header.html"' is not a partial control statement at line: 4 char: 1' is fixed by removing mako_header and _footer.

Author

File "/usr/lib/pymodules/python2.7/openerp/report/render/makohtml2html/makohtml2html.py", line 113, in format_body </body></html>'''%(body_list,body_list[0],footer,'1',len(body_list)) IndexError: list index out of range

Author

Thanks for all your time and effort @GEM. Does it work OK for you? If so would you tell me what versions you are using?

line "## -- coding: utf-8 --" you wrote and used is bad, used this I give in my first answer (which I have updated) .... Bye

the line utf8 in file python is not the good syntax, you must use # -- coding: utf-8 -- , as I wrote in the original answer I have updated, restart openerp server and update the module. Bye

you must use line # -- coding: utf-8 -- not this you use and decribe in your answer and comments.Bye

Author

One # or two ## gives the same result. Mako 0.2.4 is "active" and 0.7.1 is "non-active" via "yolk -l | grep Mako". So yes, I get past the encoding 'ascii' error, THANKS! Please update your answer to include the "pip install Mako==0.2.4" and I'll mark you as the answer.

Author

FYI, the third error that I'm working on is "RML is not available at specified location or not enough data to print (2)! (None, None, None)" which I take it means "not enough data to print." I'd added the (2) as a marker in ../service/web_services.py exp_report() to identify which of 2 exactly the same error situations is arising.

updated. Hope this will work for the last error, try to remove line mako heder xor footer in mako line, restart and update. Bye

Author

I removed the header and footer, same "not enough data" error. Trimmed .mako to "## -- encoding: utf-8 -- <html> <head> HEAD </head> <body> BODY </body> </html>" and still "no data."

Author

But let's close this one out. I've started another one that is a little more general here http://help.openerp.com/question/5087/how-do-you-make-appopenerpcom-sale_report_html-work-on-ubuntu-1210/

Author Best Answer

Add "## -- coding: utf-8 --" as the first line of the file sale_order_html.mako.

Avatar
Discard
Author

It should be noted that http://apps.openerp.com sale_report_html "Updated Jan 8, 2013 3:04:19 PM" is no longer compatible with the current Mako. Well, at least it's not compatible with Ubuntu 12.10, python-mako 0.7.1-1.