This is my problem

import json

var="FOPIC - Construção e Investimentos, Lda."


if i do
>>> json.dumps({'name': var, 'value': 1})
'{"name": "FOPIC - Constru\\u00e7\\u00e3o e Investimentos, Lda.", "value":
1}'
>>>

its ok, but i need to truncate the string to the first 18 letters

so i do

>>> json.dumps({'name': var[:18], 'value': 1})

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Python27\lib\json\encoder.py", line 201, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\lib\json\encoder.py", line 264, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc3 in position 17:
unexpected end of data
>>>


I need help ,as usual  :P

Thank you


2014-03-18 20:33 GMT+00:00 Michele Comitini <michele.comit...@gmail.com>:

> @Antonio,
>
> please create a simple example action that causes the error in your
> setup and post it here.
> something like
>
> # -*- coding: utf-8 -*-
>
> def myfunc():
>    return dict(mykey='contruções')
>
>
>
>
> 2014-03-18 15:57 GMT+01:00 António Ramos <ramstei...@gmail.com>:
> > yes i have it in my controller.py file
> >
> > # -*- coding: utf-8 -*-
> >
> >
> >
> > 2014-03-18 14:48 GMT+00:00 Leonel Câmara <leonelcam...@gmail.com>:
> >
> >> Olá António,
> >>
> >> Is your controller .py file saved in utf-8 (make sure the text editor is
> >> doing it, use "the save with encoding" option if you have it) and has
> this
> >> as the first line?
> >>
> >> # -*- coding: utf-8 -*-
> >>
> >> --
> >> Resources:
> >> - http://web2py.com
> >> - http://web2py.com/book (Documentation)
> >> - http://github.com/web2py/web2py (Source code)
> >> - https://code.google.com/p/web2py/issues/list (Report Issues)
> >> ---
> >> You received this message because you are subscribed to the Google
> Groups
> >> "web2py-users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an
> >> email to web2py+unsubscr...@googlegroups.com.
> >> For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > Resources:
> > - http://web2py.com
> > - http://web2py.com/book (Documentation)
> > - http://github.com/web2py/web2py (Source code)
> > - https://code.google.com/p/web2py/issues/list (Report Issues)
> > ---
> > You received this message because you are subscribed to the Google Groups
> > "web2py-users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to web2py+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to