I have a Python client script and was trying to fetch the records from my Skygear server database. Seems like the latest py-skygear on git already has this supported and so I installed it through git:
pip install sphinx pip install -U git+https://github.com/SkygearIO/py-skygear.git
So I tried to connect and query my table called “testing” on the database using this script (with pip installed all packages needed and environment variables saved in .env file):
import os from os.path import join, dirname from dotenv import load_dotenv from skygear.container import SkygearContainer from skygear.transmitter import HttpTransport from skygear.models import Record, RecordID from skygear.query import Query # load environment variables dotenv_path = join(dirname(__file__), ".env") load_dotenv(dotenv_path) # connect to skygear database endpoint = os.environ.get('SKYGEAR_ENDPOINT', None) master_key = os.environ.get('SKYGEAR_MASTER_KEY', None) http_transport = HttpTransport(addr=endpoint) container = SkygearContainer(endpoint=endpoint, api_key=master_key, transport=http_transport) database = container.public_database # query table with record_type (table name) "books" from database query = Query('books') result = database.query(query)
However it shows me this piece of error:
Traceback (most recent call last): File "tmp.py", line 23, in <module> result = database.query(query) File "/Users/joyz/myproject/env/lib/python3.6/site-packages/skygear/database.py", line 117, in query result = self.container.send_action('record:query', payload) File "/Users/joyz/myproject/env/lib/python3.6/site-packages/skygear/container.py", line 117, in send_action resp = self.transport.send_action(action_name, payload, url, timeout) File "/Users/joyz/myproject/env/lib/python3.6/site-packages/skygear/transmitter/http.py", line 140, in send_action raise error.SkygearException.from_dict(resp['error']) skygear.error.SkygearException: failed to construct query: got len(predicate) = 0, want at least 2
Did I misuse the query function or is it a must to set the predicate for it?