Python plugin: Error on alter (grpc._channel._Rendezvous)

I am trying out sample queries using Python plugin.

Query:

name: string @index(term) @lang .
age: int @index(int) .
friend: uid @count .

This worked fine on the browser:
Screenshot%20from%202018-06-28%2012-24-14

Same query is crashing from Python.

Code:

import pydgraph

client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)

query = """name: string @index(term) @lang .
    age: int @index(int) .
    friend: uid @count ."""

result = client.alter(query)
print(result)

Stacktrace:

ERROR:root:Exception serializing message!
Traceback (most recent call last):
  File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/grpc/_common.py", line 87, in _transform
    return transformer(message)
TypeError: descriptor 'SerializeToString' requires a 'google.protobuf.pyext._message.CMessage' object but received a 'str'
Traceback (most recent call last):
  File "/home/galaxia/Documents/bitbucket repo/Dgraph/schema.py", line 10, in <module>
    result = client.alter(query)
  File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/pydgraph/client.py", line 42, in alter
    return self.any_client().alter(op, timeout=timeout, metadata=metadata, credentials=credentials)
  File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/pydgraph/client_stub.py", line 36, in alter
    return self.stub.Alter(op, timeout=timeout, metadata=metadata, credentials=credentials)
  File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/grpc/_channel.py", line 486, in __call__
    credentials)
  File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/grpc/_channel.py", line 471, in _blocking
    raise rendezvous
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.INTERNAL, Exception serializing request!)>

this worked, any way to submit this as a query?

schema = 'name: string @index(exact) .'
op = pydgraph.Operation(schema=schema)
client.alter(op)

This is not a query. You are setting a scheme here:

query = """name: string @index(term) @lang .
    age: int @index(int) .
    friend: uid @count ."""

This is to be done:

def set_schema(client):
    schema = """
    name: string @index(exact) @lang .
    friend: uid @count .
    age: int @index(int) .
    """

You can refer to this example:

https://github.com/dgraph-io/pydgraph/blob/master/examples/simple/simple.py

ok thanks :smiley:

The browser UI was submitting it, so I was doing the same. understood.