Can't print: raise TypeError('Expected bytes') in the logs

Bug #1193563 reported by Ilia Naryzhny on 2013-06-22
100
This bug affects 20 people
Affects Status Importance Assigned to Milestone
Odoo Web (MOVED TO GITHUB)
Fix Released
Medium
OpenERP R&D Web Team
OpenERP Community Backports (Web)
High
Ronald Portier (Therp)
6.1
Undecided
Unassigned

Bug Description

We have openerp v7 installation. When I'm trying to print any page with the aid of "Print" submenu I obtain following in UI:

Uncaught SyntaxError: Unexpected end of input
http://erp.npp-alion.ru/?ts=1371848653090#id=6&view_type=form&model=product.product&menu_id=363&action=425:0

And following in the logs:

2013-06-22 07:12:50,987 24036 ERROR openerp openerp.addons.web.http.HttpRequest.dispatch: An error occurred while handling a json request
Traceback (most recent call last):
  File "/usr/openerp/addons/web/http.py", line 285, in dispatch
    r = method(self, **self.params)
  File "/usr/openerp/addons/web/controllers/main.py", line 1767, in index
    cookies={'fileToken': int(token)})
  File "/usr/openerp/addons/web/http.py", line 332, in make_response
    response.set_cookie(k, v)
  File "/usr/lib64/python2.7/site-packages/werkzeug/wrappers.py", line 960, in set_cookie
    self.charset))
  File "/usr/lib64/python2.7/site-packages/werkzeug/http.py", line 905, in dump_cookie
    value = to_bytes(value, charset)
  File "/usr/lib64/python2.7/site-packages/werkzeug/_compat.py", line 106, in to_bytes
    raise TypeError('Expected bytes')
TypeError: Expected bytes

Related branches

Hello Ilia Naryzhny,

Currently, I have checked your issue with latest trunk as well as with 7.0, But I am not able to reproduce this issue. Its working fine at all. So, Would you please check it again with and notify us if you still have any issue.

Thanks & waiting for your answer.

Changed in openobject-addons:
status: New → Incomplete

Try to install werkzeug from apt-get (python-werkzeug), this work for me.
The werkzeug to easy_install give me the same bugs.

Ilia Naryzhny (phantom-s) wrote :

I updated werkzeug package with the aid of "pip install" plus installed lates openerp. Pretty much the same problem:

2013-06-24 14:17:13,437 3340 DEBUG ? openerp.report.render.rml2pdf.customfonts: Found font DejaVuSans-BoldOblique.ttf at /usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf
2013-06-24 14:17:13,979 3340 ERROR openerp openerp.addons.web.http.HttpRequest.dispatch: An error occurred while handling a json request
Traceback (most recent call last):
  File "/usr/openerp/addons/web/http.py", line 285, in dispatch
    r = method(self, **self.params)
  File "/usr/openerp/addons/web/controllers/main.py", line 1767, in index
    cookies={'fileToken': int(token)})
  File "/usr/openerp/addons/web/http.py", line 332, in make_response
    response.set_cookie(k, v)
  File "/usr/lib64/python2.7/site-packages/werkzeug/wrappers.py", line 960, in set_cookie
    self.charset))
  File "/usr/lib64/python2.7/site-packages/werkzeug/http.py", line 905, in dump_cookie
    value = to_bytes(value, charset)
  File "/usr/lib64/python2.7/site-packages/werkzeug/_compat.py", line 106, in to_bytes
    raise TypeError('Expected bytes')
TypeError: Expected bytes
2013-06-24 14:17:14,022 3340 INFO openerp werkzeug: 127.0.0.1 - - [24/Jun/2013 14:17:14] "GET /web/report?action=%7B%22flags%22%3A%7B%22views_switcher%22%3Atrue%2C%22search_view%22%3Atrue%2C%22action_buttons%22%3Atrue%2C%22sidebar%22%3Atrue%2C%22pager%22%3Atrue%2C%22display_title%22%3Atrue%2C%22search_disable_custom_filters%22%3Atrue%7D%2C%22type%22%3A%22ir.actions.report.xml%22%2C%22datas%22%3A%7B%22ids%22%3A%5B6%5D%2C%22form%22%3A%7B%22number%22%3A1%2C%22id%22%3A12%7D%7D%2C%22report_name%22%3A%22product.price%22%2C%22context%22%3A%7B%22lang%22%3A%22ru_RU%22%2C%22tz%22%3A%22Europe%2FMoscow%22%2C%22uid%22%3A1%2C%22active_id%22%3A12%2C%22active_ids%22%3A%5B12%5D%2C%22active_model%22%3A%22mrp.product_price%22%2C%22search_disable_custom_filters%22%3Atrue%7D%2C%22menu_id%22%3Anull%7D&token=1372083282647&session_id=ca25b9e0f933486880e139244b9c8a7c HTTP/1.1" 500 -

What is your version of werkzeug?

Same error over here. It started when I upgraded Ubuntu

Just solved the mistery!!!! It works with Werkzeug 0.8.3. Try

pip install werkzeug==0.8.3

should work

The apt-get package for werkzeug is the same as Gustavo (0.8.3), and worked to me too,

so the problem must be in the version of pip (0.9.3) or in the SO, i'm using Ubuntu 13.04

Ilia Naryzhny (phantom-s) wrote :

With 0.8.3 it's working! But the latest version is 0.9.1. Are you going to update code accordingly?

I'm on gentoo... And there we are obtaining updates much quicker than twice
per year like for Ubuntu:) So... be ready for update of werkzeug to 0.9.1...

Ilia

2013/6/24 Alberto Martín - Guadaltech <email address hidden>

> The apt-get package for werkzeug is the same as Gustavo (0.8.3), and
> worked to me too,
>
> so the problem must be in the version of pip (0.9.3) or in the SO, i'm
> using Ubuntu 13.04
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1193563
>
> Title:
> Can't print: raise TypeError('Expected bytes') in the logs
>
> Status in OpenERP Addons (modules):
> Incomplete
>
> Bug description:
> We have openerp v7 installation. When I'm trying to print any page with
> the aid of "Print" submenu I obtain following in UI:
>
> Uncaught SyntaxError: Unexpected end of input
>
> http://erp.npp-alion.ru/?ts=1371848653090#id=6&view_type=form&model=product.product&menu_id=363&action=425:0
>
> And following in the logs:
>
> 2013-06-22 07:12:50,987 24036 ERROR openerp
> openerp.addons.web.http.HttpRequest.dispatch: An error occurred while
> handling a json request
> Traceback (most recent call last):
> File "/usr/openerp/addons/web/http.py", line 285, in dispatch
> r = method(self, **self.params)
> File "/usr/openerp/addons/web/controllers/main.py", line 1767, in index
> cookies={'fileToken': int(token)})
> File "/usr/openerp/addons/web/http.py", line 332, in make_response
> response.set_cookie(k, v)
> File "/usr/lib64/python2.7/site-packages/werkzeug/wrappers.py", line
> 960, in set_cookie
> self.charset))
> File "/usr/lib64/python2.7/site-packages/werkzeug/http.py", line 905,
> in dump_cookie
> value = to_bytes(value, charset)
> File "/usr/lib64/python2.7/site-packages/werkzeug/_compat.py", line
> 106, in to_bytes
> raise TypeError('Expected bytes')
> TypeError: Expected bytes
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openobject-addons/+bug/1193563/+subscriptions
>

I have the exact same error when trying to export an invoice.

And with the werkzeug version from the (debian testing) packages:

252k (diff: 4096k)('oe_sercom_dev', 1, '*', u'account.invoice', 'export_data', (...), {})
2013-06-27 14:55:20,359 29306 ERROR oe_sercom_dev openerp.addons.web.http.HttpRequest.dispatch: An error occurred while handling a json request
Traceback (most recent call last):
  File "/home/openeyedev/var/projects/oe_sercom/web/addons/web/http.py", line 285, in dispatch
    r = method(self, **self.params)
  File "/home/openeyedev/var/projects/oe_sercom/web/addons/web/controllers/main.py", line 1627, in index
    cookies={'fileToken': int(token)})
  File "/home/openeyedev/var/projects/oe_sercom/web/addons/web/http.py", line 332, in make_response
    response.set_cookie(k, v)
  File "/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 960, in set_cookie
    self.charset))
  File "/usr/lib/python2.7/dist-packages/werkzeug/http.py", line 905, in dump_cookie
    value = to_bytes(value, charset)
  File "/usr/lib/python2.7/dist-packages/werkzeug/_compat.py", line 106, in to_bytes
    raise TypeError('Expected bytes')
TypeError: Expected bytes

Changed in openobject-addons:
status: Incomplete → Confirmed

As several people report this error, I took the liberty to change the status from Incomplete to Confirmed.

Hello I think the error is in this line:

File "/usr/openerp/addons/web/controllers/main.py", line 1767, in index
    cookies={'fileToken': int(token)})

A cookie string is of course ... a string. By making the token numeric (int) instead of a string, the to_bytes method later on receives a number where it is expecting some kind of string. Hence the TypeError.

So the error is not with werkzeug, but squarely in openerp, so has to be solved there.

It is true that the error was triggered by an upgrade in werkzeug, that, as far as I can see, has to ensure better handling of the difference between python 2.x and 3.x, the whole stuff about moving to unicode strings. As this seems a worthwhile goal, we from our (the OpenERP) side should adapt.

I can reproduce the error by both printing and exporting (or trying to). Both those actions try to return a file to the client, in te one case a csv file, in the other a pdf...

I will try to submit a merge request.

affects: openobject-addons → openerp-web

Hello Ilia Naryzhny,

currently,I have installed latest werkzeug 0.9.1, and checked with trunk as well as with 7.0. And I am facing same error as i have shown you in my above video. but I am facing different traceback as below :

2013-07-12 11:06:57,928 9397 ERROR trnk openerp.addons.web.http: An exception occured during an http request
Traceback (most recent call last):
  File "/home/tch/workspace/rdtools/web/trunk/addons/web/http.py", line 414, in dispatch
    r = self._call_function(**self.params)
  File "/home/tch/workspace/rdtools/web/trunk/addons/web/http.py", line 184, in _call_function
    return self.func(*args, **kwargs)
  File "/home/tch/workspace/rdtools/web/trunk/addons/web/http.py", line 1037, in nfunc
    return func(*args, **kwargs)
TypeError: index() got an unexpected keyword argument 'session_id'

with both chrome and Firefox latest version.

So, I am confirming this issue.

Thank you.

Changed in openerp-web:
assignee: nobody → OpenERP R&D Web Team (openerp-dev-web)
importance: Undecided → Medium

Fixed in web trunk revision 3777 and web 7.0 version 3999.

Changed in openerp-web:
status: Confirmed → Fix Released

Hi Nicolas,

I inspected the your fix and it only fixes the code in one place. The same code occurs in several other places in the same file. The problem therefore still occurs for instance when creating a database backup. I am a little disappointed that you apparently did not even look at the branch that my colleague suggested, which fixes the problem in all those places.

Cheers,
Stefan.

Changed in openerp-web:
status: Fix Released → Fix Committed
Changed in openerp-web:
status: Fix Committed → Fix Released

Yes, sorry about that, I didn't see your corrections.

I had to re-create the fix because I had some problems while merging your branch but I pushed a new fix in 7.0 and trunk which is essentially the same.

Great, thanks!

no longer affects: ocb-web/7.0

Actually is still affects 6.1 Trunk Nightlies. Can someone please propose this fix for merge into the Trunk.
As it is Tagged "Mature" users would suspect that such bugs are fixed in this versions.

The fix in the official branches is still incomplete.

Changed in ocb-web:
status: New → Fix Released
Jaf Faizal (jaffaizal) wrote :

I am running openERP v6.1-1 on UBUNTU 12.04 LTS.

Had the same problem. Downgraded Werkzeug 0.8.3
Did as suggested by Gustova.

sudo pip install werkzeug==0.8.3

Now working. Can print again.

Thanks Gustova.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers