I encounter an error and I do not understand how to fix it, in localhost the error does not appear. I have a web server written with Python and I'm dealing with third party service callbacks
I use an await to get the user's document and check if it exists or not, as described in the official documentation
Here is my code:
collection = firestore_async.client().collection('xxxx')
document = collection.document(uuid)
uuid_doc = await document.get()
if uuid_doc.exists:
return "Data exists"
else:
return
Logs:
[2022-09-19 21:41:05,434] ERROR in app: Exception on /xxxx/xxxx/xxxx [GET]
Sep 19 11:41:05 PM Traceback (most recent call last):
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/flask/app.py", line 2525, in wsgi_app
Sep 19 11:41:05 PM response = self.full_dispatch_request()
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/flask/app.py", line 1822, in full_dispatch_request
Sep 19 11:41:05 PM rv = self.handle_user_exception(e)
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/flask/app.py", line 1820, in full_dispatch_request
Sep 19 11:41:05 PM rv = self.dispatch_request()
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/flask/app.py", line 1796, in dispatch_request
Sep 19 11:41:05 PM return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/asgiref/sync.py", line 218, in __call__
Sep 19 11:41:05 PM return call_result.result()
Sep 19 11:41:05 PM File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 428, in result
Sep 19 11:41:05 PM return self.__get_result()
Sep 19 11:41:05 PM File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
Sep 19 11:41:05 PM raise self._exception
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/asgiref/sync.py", line 284, in main_wrap
Sep 19 11:41:05 PM result = await self.awaitable(*args, **kwargs)
Sep 19 11:41:05 PM File "/opt/render/project/src/xxxx/xxxx.py", line 24, in index
Sep 19 11:41:05 PM uuid_doc = await document.get()
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/google/cloud/firestore_v1/async_document.py", line 370, in get
Sep 19 11:41:05 PM **kwargs,
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/google/api_core/grpc_helpers_async.py", line 168, in error_remapped_callable
Sep 19 11:41:05 PM call = callable_(*args, **kwargs)
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/grpc/aio/_channel.py", line 171, in __call__
Sep 19 11:41:05 PM self._response_deserializer, self._loop)
Sep 19 11:41:05 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/grpc/aio/_call.py", line 556, in __init__
Sep 19 11:41:05 PM self._send_unary_request())
Sep 19 11:41:05 PM File "/usr/local/lib/python3.7/asyncio/base_events.py", line 402, in create_task
Sep 19 11:41:05 PM self._check_closed()
Sep 19 11:41:05 PM File "/usr/local/lib/python3.7/asyncio/base_events.py", line 479, in _check_closed
Sep 19 11:41:05 PM raise RuntimeError('Event loop is closed')
Sep 19 11:41:05 PM RuntimeError: Event loop is closed
The highlighted error is RuntimeError: Event loop is closed, it only appears when my server is in production. I could notice that it came from the await so i removed it and it works great except i need to use it
Why this error occurs in production mode and not in localhost and how can I solve the error using the await?
Sorry if my English is boring to read, it's not my native language