[GRASS-dev] [GRASS GIS] #2532: TypeError: environment can only contain string when launching script on Windows

GRASS GIS trac at osgeo.org
Mon Jan 19 09:12:42 PST 2015


#2532: TypeError: environment can only contain string when launching script on
Windows
-------------------------+--------------------------------------------------
 Reporter:  annakrat     |       Owner:  grass-dev@…              
     Type:  defect       |      Status:  new                      
 Priority:  normal       |   Milestone:  7.0.0                    
Component:  Default      |     Version:  svn-trunk                
 Keywords:  encoding     |    Platform:  MSWindows 8              
      Cpu:  Unspecified  |  
-------------------------+--------------------------------------------------

Comment(by annakrat):

 Replying to [comment:14 glynn]:
 > Replying to [comment:13 annakrat]:
 > > So I tried to encode the command string and I get different error:
 > >
 > {{{
 > raise err
 > xml.etree.ElementTree
 > .
 > ParseError
 > }}}
 >
 > > It seems that get_interface_description returns empty xml
 >
 > Did you confirm that?

 No, when I print the string I get xml, seems to be valid:

 {{{
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE task SYSTEM "C:\Users\akratoc\Programs\GRASS GIS 7.1.svn\gui\xml
 \grass-interface.dtd">
 <task name="test_workshopá.py">
         <description>
                 Adds the values of two rasters (A + B)
         </description>
 ...
 }}}
 I don't understand what's wrong with it.

 >
 > Otherwise, my guess is that the XML is invalid due to encoding issues.
 >
 > The program name is copied verbatim into the XML, in the <task
 name="..."> tag.
 >
 > If GRASS was built with iconv support, the declared encoding of the XML
 will be UTF-8; text nodes will be convert from the locale's encoding to
 UTF-8 (and <,>,& will be converted to entities), but attribute values
 aren't converted:
 >
 > {{{
 >     fprintf(stdout, "<task name=\"%s\">\n", st->pgm_name);
 > }}}
 >
 > So, they need to be restricted to the intersection of the locale's
 encoding and UTF-8 (which probably means ASCII).
 >
 > I'm not sure that it's worth trying to support script names which
 contain non-ASCII characters. However, scripts in directories whose names
 contain non-ASCII characters need to be supported. The same applies to
 other files; e.g. we can reasonably restrict map, mapset and location
 names to ASCII, but we should support the situation where the database
 path contains non-ASCII characters.
 >
 > In any case, the GUI should be encoding the arguments which it passes to
 Popen(); it shouldn't be passing unicode values.

 Should the be encoding moved to `get_interface_description` in task.py?
 The `EncodeString` function is in gui, not in python scripting library.

 If I try to run the script (this time the script name is only ascii, but
 the path has some non-ascii characters which are in cp1252), I get the gui
 dialog and when I run it, I get an error:

 {{{
 Exception in thread Thread-28:
 Traceback (most recent call last):
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\Python27\lib\threading.py", line 810, in
 __bootstrap_inner
     self.run()
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\gui\wxpython\core\gconsole.py", line 155, in run
     self.resultQ.put((requestId, self.requestCmd.run()))
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\gui\wxpython\core\gcmd.py", line 575, in run
     env = self.env)
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\gui\wxpython\core\gcmd.py", line 161, in __init__
     args = map(EncodeString, args)
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\gui\wxpython\core\gcmd.py", line 92, in EncodeString
     return string.encode(_enc)
   File "C:\Users\akratoc\Programs\GRASS GIS
 7.1.svn\Python27\lib\encodings\cp1252.py", line 12, in
 encode
     return
 codecs.charmap_encode(input,errors,encoding_table)
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in
 position 38: ordinal not in range(128)
 }}}

 because in Popen class in
 [http://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/core/gcmd.py#L161
 gcmd.py] some of the arguments are of type `str`, some are `unicode`. So
 if encode only the unicode ones, it starts to work.

 {{{
             for i in range(len(args)):
                 if type(args[i]) != str:
                     args[i] = EncodeString(args[i])
 }}}

 So I am not sure what should I do with these results.

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2532#comment:15>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list