Search code examples
python-3.xgoogle-cloud-platformgoogle-cloud-functionsrequirements.txtgemini

Python google cloud function deployment failure - websockets


I am trying to deploy a python script from Google source code and it is failing when attempting to import create_connection from the websockets library.

Here is the top of my script. It fails during import of the gemini package, which in turn is importing websockets:

import json
import os

from gemini import PrivateClient

and my requirements.txt

gemini-python==0.2.1

The Google Cloud Functions log shows this error:

Traceback (most recent call last):
  File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
    sys.exit(_cli())
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/_cli.py", line 37, in _cli
    app = create_app(target, source, signature_type)
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 255, in create_app
    spec.loader.exec_module(source_module)
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/workspace/main.py", line 7, in <module>
    import gemini
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/gemini/__init__.py", line 3, in <module>
    from .basewebsocket import BaseWebSocket
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/gemini/basewebsocket.py", line 9, in <module>
    from websocket import create_connection, WebSocketConnectionClosedException
ImportError: cannot import name 'create_connection' from 'websocket' (/layers/google.python.pip/pip/lib/python3.8/site-packages/websocket/__init__.py)

This script runs on my Mac using Python 3.8. Not sure what to do as this seems environment specific. Any help is appreciated.


Solution

  • Cloud Functions does not support WebSockets.

    You may want to consider an alternative compute service such as Cloud Run which does