# Slash Python client

**URL:** <https://discuss.dgraph.io/t/slash-python-client/10668>\
**Category:** Dgraph Cloud\
**Tags:** client\
**Created:** [September 29, 2020, 2:11pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668 "2020-09-29T14:11:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [September 29, 2020, 2:11pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668/1 "2020-09-29T14:11:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [September 29, 2020, 3:03pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668/2 "2020-09-29T15:03:14Z")

</div>

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

```auto
import pydgraph

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

```

Tejas

---

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [October 4, 2020, 11:37am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/3 "2020-10-04T11:37:52Z")

</div>

@gja @pawan

> [@gja](#):
>
> `from_slash_endpoint`

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [October 5, 2020, 6:05am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/4 "2020-10-05T06:05:42Z")

</div>

> [@spinelsun](#):
>
> Hi there is no such a function in the library…

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.

---

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [October 5, 2020, 7:13am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/5 "2020-10-05T07:13:09Z")

</div>

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

Now I have a different problem:

```auto
_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

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [October 5, 2020, 10:19am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/6 "2020-10-05T10:19:59Z")

</div>

> [@spinelsun](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [October 5, 2020, 10:40am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/7 "2020-10-05T10:40:55Z")

</div>

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:

```auto

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}]}"
>

```

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [October 5, 2020, 11:10am UTC](https://discuss.dgraph.io/t/slash-python-client/10668/8 "2020-10-05T11:10:17Z")

</div>

> [@spinelsun](#):
>
> Ok found it thanks (it was under the class `DgraphClientStub` as a static method).

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](http://discuss.hypermode.com/t/grpc-error-when-connecting-to-slash-graphql/9363/2).

---

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [October 5, 2020, 12:19pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668/9 "2020-10-05T12:19:23Z")

</div>

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

```auto
_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:

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

```

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [October 5, 2020, 12:21pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668/10 "2020-10-05T12:21:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spinelsun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/spinelsun/32/4596_2.png) [@spinelsun](https://discuss.dgraph.io/u/spinelsun)\
**Post date:** [October 5, 2020, 12:26pm UTC](https://discuss.dgraph.io/t/slash-python-client/10668/11 "2020-10-05T12:26:41Z")

</div>

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
