Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore: Cannot get Quickstart to work #794

Closed
sandroboehme opened this issue Apr 8, 2019 · 9 comments
Closed

Firestore: Cannot get Quickstart to work #794

sandroboehme opened this issue Apr 8, 2019 · 9 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.

Comments

@sandroboehme
Copy link

sandroboehme commented Apr 8, 2019

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!

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 9, 2019
@sduskis sduskis added api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 16, 2019
@tseaver
Copy link
Contributor

tseaver commented Apr 16, 2019

@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.

@sandroboehme
Copy link
Author

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.

@tseaver
Copy link
Contributor

tseaver commented Apr 17, 2019

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

@sandroboehme
Copy link
Author

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

@sandroboehme
Copy link
Author

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

@gustavorps
Copy link

gustavorps commented Apr 28, 2022

+1

  • Linux
  • Using emulators
DEBUG:google.api_core.retry:Retrying due to 503 DNS resolution failed for "localhost:8888": UNKNOWN: Servname not supported for ai_socktype, sleeping 0.1s 
$ firebase -V
10.7.1
$ pip show google-cloud-firestore
Name: google-cloud-firestore
Version: 2.4.0
...
import typing as _T
import logging as _logging
import os as _os

from google.cloud import firestore_v1 as _firestore
from google.cloud.firestore_v1.base_document import (
    BaseDocumentReference as _BaseDocumentReference, 
)

from .. import exceptions as _exceptions

_os.environ['GRPC_DNS_RESOLVER'] = 'native'
_logger = _logging.getLogger(__name__)


class Collection:
    def __init__(self, 
        name:str,
        client: _firestore.Client,
    ):
        self.name = name
        self._client = client
        self._collection = self._client.collection(name)

    def insert_one(self, document: dict) -> _T.Tuple[int, _BaseDocumentReference]:
        span.set_attribute('self.name', self.name)
        span.set_attribute('self._client', repr(self._client))
        span.set_attribute('self._collection', repr(self._collection))
        timestamp, document_ref = self._collection.add(document)
        return timestamp, document_ref.get()

    def get(self, id: str):
        document_ref = self._collection.document(id)
        document = document_ref.get()
        if document.exists:
            return document
        raise _exceptions.RecordNotFoundError(id)


class Database:
    def __init__(self, client: _firestore.Client):
        self._client = client

    def __getattr__(self, name) -> Collection:
        return Collection(name, self._client)

    def __getitem__(self, name):
        return self.__getattr__(name)


class Client:
    _databases = {}

    def __init__(
        self,
        credential=None,
        **options
    ):
        self.options = options
        self._credential = credential

    @property
    def default_db(self):
        return self.__getdatabase('Root')

    def __getdatabase(self, name) -> Database:
        _logger.info(self._databases)
        try:
            return self._databases[name]
        except KeyError:
            client = _firestore.Client(
                credentials=self._credential,
                client_options=self.options,
            )
            self._databases[name] = Database(client)
            return self._databases[name]
        except Exception as e:
            raise e

    def __getattr__(self, name):
        return self.__getdatabase(name)

    def __getitem__(self, name):
        return self.__getattr__(name)
>>> client = Client()
>>> db = client.default_db
>>> collection = db['issue']
>>> collection.insert_one({'foo': 'bar'})

@00cyre
Copy link

00cyre commented Nov 23, 2023

just happened to me, setting environ did not solve it

@parthea parthea reopened this Nov 23, 2023
@parthea parthea transferred this issue from googleapis/google-cloud-python Nov 23, 2023
@00cyre
Copy link

00cyre commented Nov 27, 2023

solved it by not using firestore, and using realtime db instead xD

@daniel-sanche
Copy link
Contributor

Closing as this is an old issue, which I don't believe is currently impacting anyone. If anyone is still seeing this issue, let me know and I'll try to reproduce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

8 participants