Hello everyone, sorry if this is a silly question, or if this is the wrong place to ask, but I’m quite new to Couchbase AND Python, and I couldn’t find the answer anywhere else.
I have a bucket with various data, and I’m performing a couple of queries: the first one returns data, the second one finds no matching documents.
If I go to the console and I perform the queries, I get something on the line of:
query 1:
SELECT keyName FROM bucket
result:
[
{
"keyName": "value1"
},
{
"keyName": "value2"
}
]
query 2:
SELECT keyName FROM bucket WHERE unsatisfiable_condition
result:
{
"results": [],
"metrics": {
"elapsedTime": "182.0104ms",
"executionTime": "182.0104ms",
"resultCount": 0,
"resultSize": 0
}
}
Now, the question is: how do I handle the second case, with the Python SDK? I’m performing the query in this way (simplifying my code):
buckets = {}
def __getBucket(self, bucketName):
if self.buckets.has_key(bucketName):
return self.buckets[bucketName]
else:
bucket = Bucket(HOST+bucketName)
self.buckets[bucketName] = bucket
return bucket
def getRows(self, bucketName):
bucket = self.__getBucket(bucketName)
result = bucket.n1ql_query(N1QLQuery(query))
return result
while True:
try:
rows = getRows(bucketName)
for row in rows:
do_stuff(row)
except KeyboardInterrupt as e:
print str(e)
break
except Exception as e:
print str(e)
break
If I press Ctrl+C to exit, I get the following output, generated from the second “except”:
ValueFormatError: <Failed to decode bytes, Results=1, inner_cause=, C Source=(src\convert.c,222), OBJ='{\n "requestID": "1c7b22a7-9034-4e47-8a47-27c9329ad862",\n "signature": {\n "keyName": "json"\n },\n "results": [\n ],\n "status": "success",\n "metrics": {\n "elapsedTime": "10.9967ms",\n "executionTime": "10.9967ms",\n "resultCount": 0,\n "resultSize": 0\n }\n}\n'>
Why am I getting this error, and why am I getting it only when I try to exit (and not during execution time)? Am I handling things correctly?