Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get sale_report_html past Unicode decode operation of encoding 'ascii' failed at line: 0 char: 0?

By
Dale E. Moore
on 3/3/13, 1:36 PM 3,784 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?

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

Moore Works, Dale E. Moore
on 3/5/13, 2:39 AM

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

Cyril Gaspard (GEM)
on 3/9/13, 9:28 AM
2

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/5/13, 8:29 PM

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

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.

Moore Works, Dale E. Moore
on 3/7/13, 12:46 PM

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.

Moore Works, Dale E. Moore
on 3/7/13, 12:46 PM

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

Moore Works, Dale E. Moore
on 3/7/13, 12:48 PM

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

Cyril Gaspard (GEM)
on 3/7/13, 3:42 PM

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.

Moore Works, Dale E. Moore
on 3/7/13, 4:23 PM

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

Cyril Gaspard (GEM)
on 3/7/13, 5:00 PM

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

Moore Works, Dale E. Moore
on 3/7/13, 5:09 PM

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

Moore Works, Dale E. Moore
on 3/7/13, 5:10 PM

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.)

Moore Works, Dale E. Moore
on 3/7/13, 5:11 PM

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

Cyril Gaspard (GEM)
on 3/7/13, 5:49 PM

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

Cyril Gaspard (GEM)
on 3/7/13, 6:04 PM

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.

Moore Works, Dale E. Moore
on 3/8/13, 10:58 AM

'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.

Moore Works, Dale E. Moore
on 3/8/13, 10:59 AM

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

Moore Works, Dale E. Moore
on 3/8/13, 11:00 AM

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?

Moore Works, Dale E. Moore
on 3/8/13, 11:00 AM

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

Cyril Gaspard (GEM)
on 3/8/13, 4:29 PM

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

Cyril Gaspard (GEM)
on 3/8/13, 4:31 PM

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

Cyril Gaspard (GEM)
on 3/8/13, 4:51 PM

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.

Moore Works, Dale E. Moore
on 3/9/13, 9:16 AM

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.

Moore Works, Dale E. Moore
on 3/9/13, 9:22 AM

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

Cyril Gaspard (GEM)
on 3/9/13, 9:25 AM

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."

Moore Works, Dale E. Moore
on 3/9/13, 10:40 AM

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/

Moore Works, Dale E. Moore
on 3/9/13, 10:41 AM
0
Dale E. Moore
On 3/4/13, 1:22 AM

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

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.

Moore Works, Dale E. Moore
on 3/4/13, 1:32 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/3/13, 1:36 PM
Seen: 3784 times
Last updated: 3/16/15, 8:10 AM