0

I know this problem is not new, but I don't know how to resolve it. I need to convert an .opl file (vim outline format) to .mm (free mind). Point is that the original file is written in italian language so is full of accents and during the conversion using the python script (plugin) I am getting an unicode error. This is the detail

python outline_freemind.py test.otl > test.mm
File "outline_freemind.py", line 114, in <module>
    xmltree.write(sys.stdout, 'utf-8')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 815, in write
    serialize(write, self._root, encoding, qnames, namespaces)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 934, in _serialize_xml
    _serialize_xml(write, e, encoding, qnames, None)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 934, in _serialize_xml
    _serialize_xml(write, e, encoding, qnames, None)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 934, in _serialize_xml
    _serialize_xml(write, e, encoding, qnames, None)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 927, in _serialize_xml
    v = _escape_attrib(v, encoding)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1085, in _escape_attrib
    return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

I tried to insert at the beginning of the script

# -*- coding:utf-8-*-

Without success.

Chnossos
  • 9,971
  • 4
  • 28
  • 40
Enrico Pirani
  • 1,387
  • 3
  • 13
  • 22
  • It is not `coding` but `encoding` : `# -*- encoding: utf-8 -*-`. – Chnossos May 20 '14 at 16:56
  • @Chnossos [that's not correct](http://legacy.python.org/dev/peps/pep-0263/) ... although OP's error doesn't look like it has anything to do with the declared encoding of the script in any case. – Zero Piraeus May 20 '14 at 17:10
  • According to the manual (https://docs.python.org/2/howto/unicode.html) the syntax is :#!/usr/bin/env python # -*- coding: latin-1 -*- – Enrico Pirani May 20 '14 at 17:13
  • Please check likned answer, and tell us whether it worked. – jb. May 20 '14 at 18:00

1 Answers1

1

The declared encoding of your plugin is irrelevant to the problem you're having: the only purpose of the declaration is to tell the Python interpreter the encoding of the program itself, and your program contains no character outside the ASCII range, so is impossible to misinterpret.

If the problem were related to the encoding of the program, you'd get an error like this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "outline_freemind.py", line 115
SyntaxError: Non-ASCII character '\xc3' in file outline_freemind.py on line 115, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

... but since you're actually getting a UnicodeDecodeError instead, that means the error is in your plugin's handling of non-ASCII input ... so you should probably report that to the plugin's author.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
  • While this is informative, it does not attempt to solve the OP's problem; it would perhaps be more suitable as a comment. – tripleee May 20 '14 at 17:33
  • @triplee a bit long for a comment, don't you think? I agree that the answer doesn't solve OP's problem, but only debugging a third-party piece of production code will do that, which is out of scope for SO (so instead I suggested contacting the author of the code). Other comments on the question are in danger of leading OP up the wrong path; this answer hopes to help them avoid trudging too far along it. – Zero Piraeus May 20 '14 at 17:36