首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >weaviate错误代码400解析正文来自...查找对象开头的无效字符'G‘失败

weaviate错误代码400解析正文来自...查找对象开头的无效字符'G‘失败
EN

Stack Overflow用户
提问于 2020-07-26 17:23:57
回答 1查看 111关注 0票数 0

我正在尝试遵循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单元测试:

代码语言:javascript
复制
'''
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()

结果是:

代码语言:javascript
复制
John von Neumann already created
Alan Turing already created
Legends already created
----------------------------------------------------------------------
Ran 1 test in 0.370s

OK

(重新运行后)

然后我试着:

代码语言:javascript
复制
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":"parsing body body from“失败,因为无效字符'G‘正在寻找对象键字符串的开头”}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-26 21:36:20

请求需要一个JSON对象(因为Content-type: application/json),这可以通过设置-d '{ "query": "{ # GRAPHQL QUERY }" }' (docs)来添加。

因此,在您的示例中,要发送的JSON对象为:

代码语言:javascript
复制
{
  "query": 
  "{ 
     Get { 
       Things { 
         Group { 
           name uuid Members { ... on Person { name uuid } }  
         } 
       } 
     } 
  }"
}

或者完整的请求:

代码语言:javascript
复制
$ 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 } } } } } }"
    }'

结果是:

代码语言:javascript
复制
{"data":{"Get":{"Things":{"Group":[{"Members":null,"name":"Legends","uuid":"2db436b5-0557-5016-9c5f-531412adf9c6"}]}}},"errors":null}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63098344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档