Search code examples
python-3.xauthenticationgoogle-cloud-firestoregoogle-cloud-python

Cannot get Firestore Quickstart to work in 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

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


Solution

  • I could solve the problem by setting os.environ['GRPC_DNS_RESOLVER'] = 'native'