Modify

Opened 4 years ago

Closed 14 months ago

#6904 closed defect (fixed)

Genshi UnicodeDecodeError error while rendering template (unknown template location)

Reported by: thuffir Owned by: rjollos
Priority: highest Component: TicketChartsMacro
Severity: blocker Keywords:
Cc: ivanelson Trac Release: 0.12

Description (last modified by rjollos)

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 4 years ago by anonymous

  • Severity changed from normal to blocker

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 4 years ago by anonymous

  • Priority changed from normal to highest

comment:3 Changed 16 months ago by rjollos

  • Owner changed from aviram to rjollos
  • Status changed from new to assigned

comment:4 Changed 16 months ago by rjollos

  • Description modified (diff)

comment:5 Changed 16 months ago by anonymous

Please let me if any fix on this?

comment:6 Changed 16 months ago by anonymous

  • Trac Release changed from 0.11 to 0.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 16 months ago by rjollos

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

comment:8 follow-up: Changed 16 months ago by rjollos

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

comment:9 Changed 16 months ago by rjollos

  • Cc ivanelson added

ivanelson: Have you experienced this error?

comment:10 in reply to: ↑ 8 Changed 16 months ago by jun66j5

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 16 months ago by rjollos

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 16 months ago by rjollos

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

comment:13 Changed 15 months ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:14 follow-up: Changed 14 months 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 14 months ago by jun66j5

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 14 months ago by jun66j5

In 13335:

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

comment:17 follow-up: Changed 14 months ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 14 months ago by jun66j5

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 14 months ago by rjollos

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

comment:20 Changed 14 months ago by sesha

  • Resolution set to fixed
  • Status changed from reopened to closed

Thanks it works FINE.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.