weaviate error code 400 parsing body from ... failed invalid character 'G' 寻找对象的开头
weaviate error code 400 parsing body from ... failed invalid character 'G' looking for beginning of object
我正在尝试按照 https://www.semi.technology/documentation/weaviate/current/client-libs/python.html 中的步骤进行操作,结果遇到了与以下相同的问题:
parsing body body from \"\" failed, because invalid character 'G' looking for beginning of object key string
由于另一个问题从未得到答案,我试图在 weaviate 上下文中询问更多细节。
我尝试了以下 python-单元测试:
'''
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":"从 "" 解析 body 失败,因为无效字符 'G' 正在寻找对象键字符串的开头"}
请求需要一个 JSON 对象(因为 Content-type: application/json
)这可以通过设置 -d '{ "query": "{ # GRAPHQL QUERY }" }'
添加(docs)。
因此,在您的情况下,要发送的 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}
我正在尝试按照 https://www.semi.technology/documentation/weaviate/current/client-libs/python.html 中的步骤进行操作,结果遇到了与以下相同的问题:
parsing body body from \"\" failed, because invalid character 'G' looking for beginning of object key string
由于另一个问题从未得到答案,我试图在 weaviate 上下文中询问更多细节。
我尝试了以下 python-单元测试:
'''
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":"从 "" 解析 body 失败,因为无效字符 'G' 正在寻找对象键字符串的开头"}
请求需要一个 JSON 对象(因为 Content-type: application/json
)这可以通过设置 -d '{ "query": "{ # GRAPHQL QUERY }" }'
添加(docs)。
因此,在您的情况下,要发送的 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}