Google-cloud-python: Firestore: Cannot get Quickstart to work

Created on 8 Apr 2019  路  5Comments  路  Source: googleapis/google-cloud-python

I followed the quickstart guide for Firestore in Python but I couldn't get it to run as I got this error message:

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "Name resolution failure"
    debug_error_string = "{"created":"@1554833859.769886000","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2267,"referenced_errors":[{"created":"@1554833859.769576000","description":"Name resolution failure","file":"src/core/ext/filters/client_channel/request_routing.cc","file_line":165,"grpc_status":14}]}"
...
google.api_core.exceptions.ServiceUnavailable: 503 Name resolution failure

This is my code:

db = firestore.Client()
doc_ref = db.collection(u'users').document(u'alovelace')
doc_ref.set({
    u'first': u'Ada',
    u'last': u'Lovelace',
    u'born': 1815
})

# Then query for documents
users_ref = db.collection(u'users')
docs = users_ref.get()

for doc in docs:
    print(u'{} => {}'.format(doc.id, doc.to_dict()))
  1. The data is there: the viewer
  2. The environment on Mac is set like this:
    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json for authentication
  3. google-cloud-firestore is installed in a new virtualenv as described in the quickstart guide.
  4. I made sure that I'm using the right gcloud project with:
    gcloud config set project example4
  5. python --version returns Python 3.7.1
  6. My Stackoverflow question didn't got a response. But I'm happy to mark an answer as working there if I can!

There must me something simple missing. Any hints are appreciated!

question firestore awaiting information

Most helpful comment

I could solve it by setting
os.environ['GRPC_DNS_RESOLVER'] = 'native'

All 5 comments

@sandroboehme Can you please provide the full Python traceback?

Also, what version of the grpcio Python library are you using? The request_routing.cc file is removed in the current grpc repository.

Thanks for having a look into that @tseaver. That's much appreciated as I would rather like to use the client lib then the REST interface I'm using now!
I've recreated the problem and get a different error now.
google.api_core.exceptions.ServiceUnavailable: 503 DNS resolution failed

Here is the full traceback:

(env) Sandros-MacBook-Pro:python-firestore sandro$ ./env/bin/python3 run.py 
Traceback (most recent call last):
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/grpc/_channel.py", line 562, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/grpc/_channel.py", line 466, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "DNS resolution failed"
        debug_error_string = "{"created":"@1555525377.166056000","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2715,"referenced_errors":[{"created":"@1555525377.166053000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":335,"referenced_errors":[{"created":"@1555525377.166052000","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":326,"grpc_status":14,"referenced_errors":[{"created":"@1555525377.165796000","description":"C-ares status is not ARES_SUCCESS: DNS query cancelled","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":240,"referenced_errors":[{"created":"@1555525377.165790000","description":"C-ares status is not ARES_SUCCESS: DNS query cancelled","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":240}]}]}]}]}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "run.py", line 14, in <module>
    u'born': 1815
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/cloud/firestore_v1/document.py", line 233, in set
    write_results = batch.commit()
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/cloud/firestore_v1/batch.py", line 148, in commit
    metadata=self._client._rpc_metadata,
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/cloud/firestore_v1/gapic/firestore_client.py", line 946, in commit
    request, retry=retry, timeout=timeout, metadata=metadata
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
    return wrapped_func(*args, **kwargs)
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/retry.py", line 270, in retry_wrapped_func
    on_error=on_error,
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/retry.py", line 179, in retry_target
    return target()
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
    return func(*args, **kwargs)
  File "/Users/sandro/developing/learning/python-firestore/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 DNS resolution failed

I've pushed my example into this repo:
https://github.com/sandroboehme/python-firestore
But at the end I think it is as easy as it can get.

The error descriptions you are reporting (Name resolution failure, DNS resolution failed) seem to imply that the library cannot resolve the endpoint hostname, which should be firestore.googleapis.com. Can you try pinging that host from the machine where your application is running, e.g.:

$ ping firestore.googleapis.com

It does resolve to an IP address at the host where the application is running. But there is a CNAME to googleapis.l.google.com. Maybe this is a problem?

$ ping firestore.googleapis.com
PING googleapis.l.google.com (172.217.22.10): 56 data bytes
64 bytes from 172.217.22.10: icmp_seq=0 ttl=52 time=39.143 ms
$ dig firestore.googleapis.com

; <<>> DiG 9.8.3-P1 <<>> firestore.googleapis.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51844
;; flags: qr rd ra; QUERY: 1, ANSWER: 17, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;firestore.googleapis.com.  IN  A

;; ANSWER SECTION:
firestore.googleapis.com. 3599  IN  CNAME   googleapis.l.google.com.
googleapis.l.google.com. 299    IN  A   172.217.22.106
googleapis.l.google.com. 299    IN  A   172.217.16.202
googleapis.l.google.com. 299    IN  A   172.217.18.106
googleapis.l.google.com. 299    IN  A   172.217.23.170
googleapis.l.google.com. 299    IN  A   172.217.21.202
googleapis.l.google.com. 299    IN  A   216.58.205.234
googleapis.l.google.com. 299    IN  A   172.217.21.234
googleapis.l.google.com. 299    IN  A   172.217.22.10
googleapis.l.google.com. 299    IN  A   172.217.18.10
googleapis.l.google.com. 299    IN  A   172.217.18.170
googleapis.l.google.com. 299    IN  A   172.217.23.138
googleapis.l.google.com. 299    IN  A   216.58.206.10
googleapis.l.google.com. 299    IN  A   216.58.207.74
googleapis.l.google.com. 299    IN  A   172.217.16.170
googleapis.l.google.com. 299    IN  A   216.58.208.42
googleapis.l.google.com. 299    IN  A   172.217.16.138

;; Query time: 54 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Apr 18 22:20:36 2019
;; MSG SIZE  rcvd: 332

I could solve it by setting
os.environ['GRPC_DNS_RESOLVER'] = 'native'

Was this page helpful?
0 / 5 - 0 ratings