0

I am trying to follow the steps at https://www.semi.technology/documentation/weaviate/current/client-libs/python.html and end up with the same problem as in:

parsing body body from \"\" failed, because invalid character 'G' looking for beginning of object key string

Since the other question never got an answer i am trying to ask with more detail in the weaviate context.

I tried the following python-unit test:

'''
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()

with the result:

John von Neumann already created
Alan Turing already created
Legends already created
----------------------------------------------------------------------
Ran 1 test in 0.370s

OK

(after rerunning)

Then i try:

curl http://localhost:8080/v1/graphql -X POST -H 'Content-type: application/json' -d '
{
  Get {
    Things {
      Group {
        name
        uuid
        Members {
          ... on Person {
            name
            uuid
          }
        }
      }
    }
  }
}'

getting the error: {"code":400,"message":"parsing body body from "" failed, because invalid character 'G' looking for beginning of object key string"}

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • Note that the header states that you'll be sending JSON but the body is GraphQL. If you want to use curl check: https://www.semi.technology/documentation/weaviate/current/query-data/get.html#define-a-query maybe it is easier if you use Python though: https://www.semi.technology/documentation/weaviate/current/client-libs/python.html#query – Bob van Luijt Jul 26 '20 at 09:49
  • @BobvanLuijt thx for the swift answer. I don't get this. I tried to simply copy the command from your example page. Please answer with the correct command or update the documentation - this is currently a showstopper for my progress. – Wolfgang Fahl Jul 26 '20 at 12:37
  • You're welcome, I've added a complete answer – Bob van Luijt Jul 26 '20 at 13:36
  • I can't use the python code as long as i get weaviate.exceptions.UnexpectedStatusCodeException: Create class {'error': [{'message': "Name 'Person' already used as a name for a Thing class"}]} - and there is no example to cleanup up schemas and instances before starting. My python unit tests keep throwing exceptions all over because of the missing "clean start" point. – Wolfgang Fahl Jul 26 '20 at 14:17

1 Answers1

1

The request expects a JSON object (because of Content-type: application/json) this can be added by setting -d '{ "query": "{ # GRAPHQL QUERY }" }' (docs).

So in your case, the JSON object to send is:

{
  "query": 
  "{ 
     Get { 
       Things { 
         Group { 
           name uuid Members { ... on Person { name uuid } }  
         } 
       } 
     } 
  }"
}

Or the complete request:

$ 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 } } } } } }"
    }'

with the result:

{"data":{"Get":{"Things":{"Group":[{"Members":null,"name":"Legends","uuid":"2db436b5-0557-5016-9c5f-531412adf9c6"}]}}},"errors":null}
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101