Search code examples
pythonorientdbpyorient

python UnicodeDecodeError on long query using pyorient


I'm using OrientDB and pyorient to query it using python my issue raised when trying to make a long query like :

select * from (traverse in('written_on') from (select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) ) where @class='Comment'

an UcodingDecodingError happens here is my code :

$ python 
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyorient 
>>> client = pyorient.OrientDB('localhost',2424)
>>> client.connect('root','root')
10
>>> db = client.db_open('DummyData','root','root')
>>> persons=client.query('select * from person')
>>> for person in persons:
...     print person.name
... 
[GOOD RESULT]
>>> posts=client.query('select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) where @class='Post')
  File "<stdin>", line 1
    posts=client.query('select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) where @class='Post')
                                                            ^
SyntaxError: invalid syntax
>>> posts=client.query("select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) where @class='Post'")
>>> for post in posts:
...     print post.content
... 
[ANOTHER GOOD RESULT]
>>> comments=client.query("select * from (traverse in('written_on') from (select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) ) where @class='Comment'")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyorient/orient.py", line 212, in query
    .prepare(( QUERY_SYNC, ) + args).send().fetch_response()
  File "/usr/local/lib/python2.7/dist-packages/pyorient/utils.py", line 47, in wrap_function
    return wrap(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyorient/utils.py", line 60, in wrap_function
    return wrap(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyorient/messages/commands.py", line 131, in prepare
    return super( CommandMessage, self ).prepare()
  File "/usr/local/lib/python2.7/dist-packages/pyorient/messages/base.py", line 72, in prepare
    self._encode_field( x ) for x in self._fields_definition
  File "/usr/local/lib/python2.7/dist-packages/pyorient/messages/base.py", line 72, in <genexpr>
    self._encode_field( x ) for x in self._fields_definition
  File "/usr/local/lib/python2.7/dist-packages/pyorient/messages/base.py", line 200, in _encode_field
    buf = v.encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9e in position 65: ordinal not in range(128)
>>> 

although the last query runs on the OrientDB Studio and retrieve right result, but when trying to do this in python this error happens.

Note: the data stored in the database is written in Arabic.


Solution

  • You have an old version, at least before Oct 18, 2014. This bug should be fixed in latest versions.

    Commit SHA of Bug Fix