Modify

Opened 14 years ago

Closed 11 years ago

#6904 closed defect (fixed)

Genshi UnicodeDecodeError error while rendering template (unknown template location)

Reported by: thuffir Owned by: Ryan J Ollos
Priority: highest Component: TicketChartsMacro
Severity: blocker Keywords:
Cc: Ivanelson Nunes Trac Release: 0.12

Description (last modified by Ryan J Ollos)

I have managed to install the plugin, but every time I try to call the macro I get the following error:

Trac Error

Genshi UnicodeDecodeError error while rendering template (unknown template location)

Any Idea?

Attachments (0)

Change History (20)

comment:1 Changed 13 years ago by anonymous

Severity: normalblocker

same here...since thuffir is waiting for 8 months! I guess theres no hope of a fix either.

2010-11-25 16:35:47,252 Trac[formatter] DEBUG: Executing Wiki macro TicketChart by provider <TicketCharts.TicketChart object at 0x0344E910>
2010-11-25 16:35:47,273 Trac[formatter] ERROR: Macro TicketChart(type = pie, factor = milestone) failed: 
Traceback (most recent call last):
  File "C:\Program Files\BitNami Trac Stack\trac\Lib\site-packages\Trac-0.11.6-py2.5.egg\trac\wiki\formatter.py", line 484, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "C:\Program Files\BitNami Trac Stack\trac\Lib\site-packages\Trac-0.11.6-py2.5.egg\trac\wiki\formatter.py", line 180, in process
    text = self.processor(text)
  File "C:\Program Files\BitNami Trac Stack\trac\Lib\site-packages\Trac-0.11.6-py2.5.egg\trac\wiki\formatter.py", line 167, in _macro_processor
    text)
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 460, in expand_macro
    return create_graph(formatter.req, formatter.env, args)
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 404, in create_graph
    chart, chart_div_id, additional_html = chart_creation[args['type']](env, db, args)
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 391, in pie_graph
    return _pie_graph(env, db, args['factor'], query = args.get('query'), title = args.get('title'))
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 386, in _pie_graph
    on_click_html = _create_pie_graph_on_click_html(env, ticket_stats, factor, query, on_click_function_name)
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 355, in _create_pie_graph_on_click_html
    'array_name' : array_name,
  File "c:\program files\bitnami trac stack\python\lib\site-packages\TicketCharts.py", line 142, in _safe_evaluate
    return string.Template(string_object).safe_substitute(mapping, **kw)
  File "C:\PROGRA~1\BITNAM~1\apache2\bin\lib\string.py", line 203, in safe_substitute
    return self.pattern.sub(convert, self.template)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xdb in position 27: ordinal not in range(128)
2010-11-25 16:35:47,275 Trac[main] WARNING: HTTPInternalError: 500 Trac Error (Genshi UnicodeDecodeError error while rendering template (unknown template location))

comment:2 Changed 13 years ago by anonymous

Priority: normalhighest

comment:3 Changed 11 years ago by Ryan J Ollos

Owner: changed from aviram to Ryan J Ollos
Status: newassigned

comment:4 Changed 11 years ago by Ryan J Ollos

Description: modified (diff)

comment:5 Changed 11 years ago by anonymous

Please let me if any fix on this?

comment:6 Changed 11 years ago by anonymous

Trac Release: 0.110.12

i am also getting same error while adding macro template to wiki page. please let me know if any fix on this.

comment:7 Changed 11 years ago by Ryan J Ollos

Please post the macro call markup that results in an error.

comment:8 Changed 11 years ago by Ryan J Ollos

(In [13247]) Refs #6904: Don't cast as a string, which can cause UnicodeDecode errors.

comment:9 Changed 11 years ago by Ryan J Ollos

Cc: Ivanelson Nunes added; anonymous removed

ivanelson: Have you experienced this error?

comment:10 in reply to:  8 Changed 11 years ago by Jun Omae

Replying to rjollos:

(In [13247]) Refs #6904: Don't cast as a string, which can cause UnicodeDecode errors.

I think that it would be simple to use to_unicode and to_json (untested). Also to_js_string is available since Trac 0.12.4.

  • ticketcharts/TicketCharts.py

     
    1818from trac.web.chrome import ITemplateProvider
    1919from trac.wiki.macros import WikiMacroBase
    2020from trac.ticket.query import Query
     21from trac.util.presentation import to_json
     22from trac.util.text import to_unicode
    2123
    2224import openFlashChart
    2325from openFlashChart_varieties import (
     
    185187    return list(set(iterable))
    186188
    187189
    188 def _create_javascript_array(array_name, values,
    189                              function=lambda x: x and unicode(x) or ''):
    190     from trac.util.text import to_js_string
    191     array_values = ', '.join([to_js_string(function(value))
    192                               for value in values])
    193     return 'var %s = new Array(%s)' % (array_name, array_values)
     190def _create_javascript_array(array_name, values, function=to_unicode):
     191    return 'var %s = %s' % (array_name, to_json(map(function, values)))
    194192
    195193
    196194def _create_query_object(env, query, required_columns=None):

comment:11 Changed 11 years ago by Ryan J Ollos

Thanks, I'll test it out. I'm not proficient with unicode or the trac.util.text module, so the hints are appreciated.

comment:12 Changed 11 years ago by Ryan J Ollos

(In [13250]) Refs #6904, #11072: Refactoring and improved backward compatibility for changes in [13247] and [13248], suggested by Jun Omae (jun66j5).

comment:13 Changed 11 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

comment:14 Changed 11 years ago by lbolla@…

This bug is still reproducible for me. I tracked it down to _get_random_string, whereas a non-utf8 string is generated. I am not sure why this happens, but my quick-and-dirty fix is to change _get_random_string in TicketCharts.py like that:

def _get_random_string(length):
    #return ''.join([random.choice(string.letters + string.digits)
    #                for i in xrange(length)])
    return str(random.randrange(111111111, 999999999))

comment:15 in reply to:  14 Changed 11 years ago by Jun Omae

Replying to lbolla@…:

I tracked it down to _get_random_string, whereas a non-utf8 string is generated. I am not sure why this happens, but my quick-and-dirty fix is to change _get_random_string in TicketCharts.py like that:

Good catch! The behavior is caused that string.letters is locale-dependent.

>>> locale.setlocale(locale.LC_ALL, 'de_DE')
'de_DE'
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xaa\xb5\xba\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'

I would like to use trac.util.hex_entropy instead of _get_random_string. I'll fix it shortly.

comment:16 Changed 11 years ago by Jun Omae

In 13335:

refs #6904: fixed UnicodeDecodeError, _get_random_string generates a 8-bit string if non en-US locale

comment:17 Changed 11 years ago by anonymous

Resolution: fixed
Status: closedreopened

Still i am getting the same error while adding macro template to wiki page.

Trac Error

Genshi UnicodeDecodeError error while rendering template (unknown template location)

Please let me whether it is fixed or any other solution?

Thanks sesha

comment:18 in reply to:  17 Changed 11 years ago by Jun Omae

Resolution: fixed
Status: closedreopened

Replying to anonymous:

Still i am getting the same error while adding macro template to wiki page.

Could you please provide the details to reproduce it? e.g. trac.log, system information, the parameters for the macro, etc....

comment:19 Changed 11 years ago by Ryan J Ollos

Any idea why both comment:17 and comment:18 show ticket resolution and status change?

comment:20 Changed 11 years ago by sesha

Resolution: fixed
Status: reopenedclosed

Thanks it works FINE.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.