weaviate код ошибки 400, анализирующий тело из ... неудачного недопустимого символа 'G', ищущего начало объекта
Я пытаюсь выполнить шаги на https://www.semi.technology/documentation/weaviate/current/client-libs/python.html и получаю ту же проблему, что и в:
Поскольку на другой вопрос так и не был дан ответ, я пытаюсь задать более подробный вопрос в тканевом контексте.
Я пробовал следующий тест python-unit:
'''
Created on 24.07.2020
@author: wf
'''
import unittest
import weaviate
class TestWeaviate(unittest.TestCase):
# https://www.semi.technology/documentation/weaviate/current/client-libs/python.html
def setUp(self):
pass
def tearDown(self):
pass
def testWeaviate(self):
''' see https://www.semi.technology/documentation/weaviate/current/client-libs/python.html '''
client = weaviate.Client("http://localhost:8080")
try:
client.create_schema("https://raw.githubusercontent.com/semi-technologies/weaviate-python-client/master/documentation/getting_started/people_schema.json")
except:
pass
entries=[
[ {"name": "John von Neumann"}, "Person", "b36268d4-a6b5-5274-985f-45f13ce0c642"],
[ {"name": "Alan Turing"}, "Person", "1c9cd584-88fe-5010-83d0-017cb3fcb446"],
[ {"name": "Legends"}, "Group", "2db436b5-0557-5016-9c5f-531412adf9c6" ]
]
for entry in entries:
dict,type,uid=entry
try:
client.create(dict,type,uid)
except weaviate.exceptions.ThingAlreadyExistsException as taee:
print ("%s already created" % dict['name'])
pass
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
с результатом:
John von Neumann already created
Alan Turing already created
Legends already created
----------------------------------------------------------------------
Ran 1 test in 0.370s
OK
(после перезапуска)
Тогда я пробую:
curl http://localhost:8080/v1/graphql -X POST -H 'Content-type: application/json' -d '
{
Get {
Things {
Group {
name
uuid
Members {
... on Person {
name
uuid
}
}
}
}
}
}'
получение ошибки: {"code":400,"message":"синтаксический анализ тела из" "не удалось, поскольку недопустимый символ 'G' ищет начало ключевой строки объекта"}
1 ответ
Решение
Запрос ожидает объект JSON (из-за Content-type: application/json
) это можно добавить, установив -d '{ "query": "{ # GRAPHQL QUERY }" }'
(документы).
Итак, в вашем случае объект JSON для отправки:
{
"query":
"{
Get {
Things {
Group {
name uuid Members { ... on Person { name uuid } }
}
}
}
}"
}
Или полный запрос:
$ curl http://localhost:8080/v1/graphql -X POST -H 'Content-type: application/json' -d '{
"query": "{ Get { Things { Group { name uuid Members { ... on Person { name uuid } } } } } }"
}'
с результатом:
{"data":{"Get":{"Things":{"Group":[{"Members":null,"name":"Legends","uuid":"2db436b5-0557-5016-9c5f-531412adf9c6"}]}}},"errors":null}