Login using pydgraph

Hi,I am using ACL , now I need to use pydgraph for data query, add and delete operation.So how do I initialize the authentication user information?Before using ACL, I can use client_ Stubs directly operate data like this:
捕获

Now,error like this

Error: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = “no accessJwt available”
debug_error_string = “{“created”:”@1611132551.997000000",“description”:“Error received from peer ipv4: localhost:9080”,“file”:“src/core/lib/surface/call.cc”,“file_line”:1055,“grpc_message”:“no accessJwt available”,“grpc_status”:16}"

You need to set-up groot

You can use following functions:

def getJWTForGroot():
    url = 'http://localhost:8080/admin'
    q = """mutation {login(userId: "groot", password: "password") {
            response {
                accessJWT
                refreshJWT
            }
        }
    }"""
    headers = {
    'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, json = {'query': q})
    json_data = json.loads(response.text)
    return json_data['data']['login']['response']

def setUpGroot(client):
    client.login("groot", "password")
    accessJWTForGroot = getJWTForGroot()['accessJWT']

After creating users and groups, you can modify the getJWTForGroot to get JWT tokens for other users.

1 Like

Thank you @Anurag for your help, I will try