[sword-devel] python3 , StrongsGreek and unicodeDecodeError
Matěj Cepl
mcepl at cepl.eu
Thu Jun 20 14:35:36 EDT 2019
On 2019-06-16, 19:02 GMT, pierre amadio wrote:
> Playing with the python3 Sword module I hit a problem that
> I did not have with python2 when dealing with Strongs
> definition such as G1140 (daimonion). It looks like the 'æ'
> character is causing problem.
>
> This example works with python2, but generate an error when
> ran wiht python3:
>
> ##########
> import Sword
> library = Sword.SWMgr()
> target=library.getModule("StrongsGreek")
> vk=Sword.SWKey("1140")
> target.setKey(vk)
> strongEntry=target.renderText().getRawData()
> ###########
>
> File "/usr/local/sword/python3/lib64/python3.4/site-packages/Sword.py",
> line 128, in getRawData
> def getRawData(self): return _Sword.SWBuf_getRawData(self)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position
> 73: invalid continuation byte
>
> Anyone knows how to be able to catch the content of this entry in a
> python variable ?
This is usually problem with C API providing C-style strings
(bytes in Pythonesque) and Python expects Python strings (str in
Pythonesque). Also, what encoding C library uses? Is it really
UTF-8? If not (and it is for example Windows-friendly UTF-16)
str.decode('utf-16') conversion must be done to get proper
Python str object.
Best,
Matěj
--
https://matej.ceplovi.cz/blog/, Jabber: mcepl at ceplovi.cz
GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8
He loves nature in spite of what it did to him.
-- Forrest Tucker
More information about the sword-devel
mailing list