Slash Python client

Hi,

Is there any python client for Slash-GQL?
if not how can I connect my python backend to slash (I am using Django)

Thanks

Hi @spinelsun,

If you are using the GraphQL API, you can use any GraphQL compatible library.
If you would like to use the DQL (earlier GraphQL±) interface, you can use pydgraph to connect. See below for a snippet

import pydgraph

client_stub = pydgraph.DgraphClientStub.from_slash_endpoint('https://your-name.whatever/graphql', '<apiToken>')
client = pydgraph.DgraphClient(client_stub)

Tejas

1 Like

@gja @pawan

Hi there is no such a function in the library…
Can you supply a different example?
I don’t succeed to create a client that works.
I always get the following error:

InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "DNS resolution failed for service: <my_endpoint>"
        debug_error_string = "{"created":"@1601822133.576779591","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":214,"referenced_errors":[{"created":"@1601822133.576778035","description":"<my_endpoint>","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":377,"grpc_status":14,"referenced_errors":[{"created":"@1601822133.576729987","description":"C-ares status is not ARES_SUCCESS qtype=A name=https is_balancer=0: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":287}]}]}"

I run my code inside a docker container if that say something

This was released in the 20.07 pydgraph version, so if you are using an older version of pygraph you will have to update to the latest.

Ok found it thanks (it was under the class DgraphClientStub as a static method).

Now I have a different problem:

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses"

I think it is a certificates problem
Regular https requests are working

Can you try again after a couple of minutes? Sometimes your cluster is asleep if idle for long and it takes time before it can start accepting requests

I tried that but it didn’t work.
When I run queries in Slash Api Explorer it works. Same if I send https requests.
Here is the full stack trace:


txn.query(query)
---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last)
<ipython-input-4-6cdcfeff338a> in <module>
----> 1 txn.query(query)

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/pydgraph/txn.py in query(self, query, variables, timeout, metadata, credentials)
     60         """Executes a query operation."""
     61         req = self.create_request(query=query, variables=variables)
---> 62         return self.do_request(req, timeout=timeout, metadata=metadata, credentials=credentials)
     63 
     64     def async_query(self, query, variables=None, timeout=None, metadata=None, credentials=None):

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/pydgraph/txn.py in do_request(self, request, timeout, metadata, credentials)
    123                 pass
    124 
--> 125             self._common_except_mutate(query_error)
    126 
    127         if request.commit_now:

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/pydgraph/txn.py in _common_except_mutate(error)
    220             raise errors.ConnectionError(error)
    221 
--> 222         raise error
    223 
    224     def commit(self, timeout=None, metadata=None, credentials=None):

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/pydgraph/txn.py in do_request(self, request, timeout, metadata, credentials)
     99         query_error = None
    100         try:
--> 101             response = self._dc.query(request, timeout=timeout,
    102                                       metadata=new_metadata,
    103                                       credentials=credentials)

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/pydgraph/client_stub.py in query(self, req, timeout, metadata, credentials)
     55     def query(self, req, timeout=None, metadata=None, credentials=None):
     56         """Runs query or mutate operation."""
---> 57         return self.stub.Query(req, timeout=timeout, metadata=metadata,
     58                                credentials=credentials)
     59 

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/grpc/_channel.py in __call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
    824         state, call, = self._blocking(request, timeout, metadata, credentials,
    825                                       wait_for_ready, compression)
--> 826         return _end_unary_response_blocking(state, call, False, None)
    827 
    828     def with_call(self,

~/.local/share/virtualenvs/ork_backend-lt4clrXI/lib/python3.8/site-packages/grpc/_channel.py in _end_unary_response_blocking(state, call, with_call, deadline)
    727             return state.response
    728     else:
--> 729         raise _InactiveRpcError(state)
    730 
    731 

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses"
	debug_error_string = "{"created":"@1601894314.766424955","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4133,"referenced_errors":[{"created":"@1601894314.766417875","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":397,"grpc_status":14}]}"
>

Thanks, I’ve updated my response. I’m sorry for the bad answer.

Which version of GRPC are you using? We’ve noticed issues with GRPC > 1.19. Please see GRPC error when connecting to Slash Graphql - #2 by gja.

I used 1.32.0 so I downgraded it and now I have this problem:

_Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "line 2 column 12: Expected Left round brackets. Got: lex.Item [6] "{" at 2:12"
	debug_error_string = "{"created":"@1601900197.547795510","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1039,"grpc_message":"line 2 column 12: Expected Left round brackets. Got: lex.Item [6] "{" at 2:12","grpc_status":2}"

This is the query:

query ="""
query MyQuery {
  queryUser {
    username
    email
  }
}
"""

Are you trying to fire a GraphQL query or a DQL (GraphQL±) query? The GRPC endpoint is only for DQL. You can just use any HTTP Client to hit the GraphQL endpoint, no need for pydgraph.

Haa I understand.
Ok I thought it can run both of them.
Well it will be nice if pydgraph would be able to run both types of queries since graphql can accept them