这是pyorient github中已关闭的问题#211的摘录。虽然,它可能有一些已经答案,但我在这里发布了这个,因为错误不是不言而喻的,并提供了使用pyorient和测试类的存在的示例。 所以这是摘录:
我正在测试如何查询类的存在,所以我正在使用动态db作为GRAPH example here
PyOrientCommandException: -
然后, 使用db_name'动物'查询数据库时我收到了以下异常响应(在此处未描述的其他情况下也会发生):
sql_query = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}')".format('Animal')
client.query(sql_query)
我的查询测试是否存在类:
---------------------------------------------------------------------------
PyOrientCommandException Traceback (most recent call last)
<ipython-input-21-a6b7ac6435cb> in <module>()
----> 1 client.query(sql_query)
/home/jo/anaconda3/envs/aenv/lib/python3.5/site-packages/pyorient/orient.py in query(self, *args)
417 def query(self, *args):
418 return self.get_message("CommandMessage") \
--> 419 .prepare(( QUERY_SYNC, ) + args).send().fetch_response()
420
421 def query_async(self, *args):
/home/jo/anaconda3/envs/aenv/lib/python3.5/site-packages/pyorient/messages/commands.py in fetch_response(self)
142
143 # decode header only
--> 144 super( CommandMessage, self ).fetch_response()
145
146 if self._command_type == QUERY_ASYNC:
/home/jo/anaconda3/envs/aenv/lib/python3.5/site-packages/pyorient/messages/base.py in fetch_response(self, *_continue)
259 # already fetched, get last results as cache info
260 elif len(self._body) is 0:
--> 261 self._decode_all()
262 self.dump_streams()
263 return self._body
/home/jo/anaconda3/envs/aenv/lib/python3.5/site-packages/pyorient/messages/base.py in _decode_all(self)
243
244 def _decode_all(self):
--> 245 self._decode_header()
246 self._decode_body()
247
/home/jo/anaconda3/envs/aenv/lib/python3.5/site-packages/pyorient/messages/base.py in _decode_header(self)
176 raise PyOrientCommandException(
177 exception_class.decode( 'utf8' ),
--> 178 [ exception_message.decode( 'utf8' ) ]
179 )
180
PyOrientCommandException: -
完整输出错误:
utf8
是否会像获得一个影子一样?解码无法识别的$stat = $this->db->prepare('INSERT INTO students (sName, phone, email, image) VALUES (:sName, :phone, :email, :img)');
字符?
我正在使用Jupyter笔记本上的代码运行Ubuntu 16.04,ANACONDA python发行版3.5,pyorient v.1.4.9
任何帮助?
答案 0 :(得分:0)
我在查询中发现了一个错误,即添加了一个额外的括号'('
sql_query_with_error = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}')".format('Animal')
正确的版本:
sql_query = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}'".format('Animal')
但现在我有一个timeout: timed
没有任何结果。
超时似乎与使用:
有关client.set_session_token(True)
而不是查询。我在笔记本中重新启动内核并再次运行脚本,现在我得到了预期的结果:
result = client.query("SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = 'Animal'")[0]
result.oRecordData
结果输出:
{'abstract': False,
'clusterIds': [17, 18, 19, 20],
'clusterSelection': 'round-robin',
'customFields': None,
'defaultClusterId': 17,
'description': None,
'name': 'Animal',
'overSize': 0.0,
'properties': [],
'shortName': None,
'strictMode': False,
'superClass': 'V',
'superClasses': ['V']}
所以我想我需要更新令牌以持续更长时间