我正在使用 OrientDB 和 pyorient 使用 python 来查询它我在尝试进行长查询时提出的问题,例如:
select * from (traverse in('written_on') from (select * from (traverse in('posted_by') from (select * from person where @rid=#14:0) ) ) where @class='Comment'
UcodingDecodingError 发生在这里是我的代码:
$ 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)
>>>
尽管最后一个查询在 OrientDB Studio 上运行并检索到正确的结果,但是当尝试在 python 中执行此操作时会发生此错误。
注意:存储在数据库中的数据是用阿拉伯语编写的。