【问题标题】:Error deploying Python function using Google Cloud Functions using dependencies使用依赖项使用 Google Cloud Functions 部署 Python 函数时出错
【发布时间】:2019-05-12 17:38:13
【问题描述】:

我正在尝试使用 Python 3.7 部署一个简单的函数。我的设置如下所示:

ma​​in.py

from firebase import firebase

def hello_world(request):
    if request.method == 'POST':
        return request.get_json().get('username')
    return f'Hello world!'

requirements.txt

# Function dependencies, for example:
# package>=version
requests==1.1.0
python-firebase==1.2

部署时出现以下错误:

Deployment failure:
Function failed on loading user code. Error message: Code in file main.py can't be loaded.
Detailed stack trace: Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 305, in check_or_load_user_function
    _function_handler.load_user_function()
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 184, in load_user_function
    spec.loader.exec_module(main)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/user_code/main.py", line 1, in <module>
    from firebase import firebase
  File "/env/local/lib/python3.7/site-packages/firebase/__init__.py", line 3
    from .async import process_pool
              ^
SyntaxError: invalid syntax

我该如何解决这个问题?我列出了所有必需的依赖项。任何帮助表示赞赏。

【问题讨论】:

    标签: python google-cloud-platform google-cloud-functions


    【解决方案1】:

    python-firebase 项目是由第三方开发人员提供的last released on March 21, 2014,不支持 Python 3.7。具体来说,它使用了新的保留关键字async/await

    您可能想改用 google-cloud-firestore 客户端库,它由 Google 维护和支持。

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 1970-01-01
      • 2020-01-19
      • 2019-01-04
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多