Jobel
Jobel

Reputation: 643

PyOrientCommandException: - : while test for the existence of a class #221

This is the extract of a closed issue#211 in the pyorient github. Although, it may be had some already answers, I posted this one here as the error was not self evident and provides an example of using pyorient and testing for the existence of a class. So here it is the extract:

I was testing how to query for the existance of a class, so I was playing with the Animals db used as GRAPH example here

### Create the Vertex Animal
cluster_id = client.command("create class Animal extends V")
print(cluster_id)
### Insert a new value
client.command("insert into Animal set name = 'rat', specie = 'rodent'")

Then, when querying the db using the db_name 'Animals' I received the following exception response (which it also occurs in other situations not described here):

PyOrientCommandException:  - 

my query to test for the existence of the class:

sql_query = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}')".format('Animal')
client.query(sql_query)

The full output error:

---------------------------------------------------------------------------
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:  - 

would it be like getting a 'shadow' utf8 character that decoding is not recognizing? I am running Ubuntu 16.04 with the code on a Jupyter notebook, ANACONDA python distribution 3.5, with pyorient v.1.4.9

Any help?

Upvotes: 0

Views: 381

Answers (1)

Jobel
Jobel

Reputation: 643

I found an error on my query that was adding an extra parenthesis '('

sql_query_with_error = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}')".format('Animal')

the correct version:

sql_query = "SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = '{}'".format('Animal')

but now I have a timeout: timed out without having any results back.

The timeout seems to be related to the use of:

client.set_session_token(True)

and not to the query. I restarted the kernel in my notebook and run again the script and now I have the expected result:

result = client.query("SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = 'Animal'")[0]
result.oRecordData

result output:

{'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']}

So I guess that I need to update the token to last more time

Upvotes: 0

Related Questions