【问题标题】:EOFError when deploying google cloud function部署谷歌云功能时出现EOFError
【发布时间】:2021-10-06 01:28:07
【问题描述】:

我有以下main.py 文件,该文件在通过网站创建时有效。 当我尝试通过 gcloud 执行相同操作时,我收到关于 EOFError: EOF when reading a line; Error ID: c84b3231 的错误

我使用的命令是gcloud functions deploy xpto --project=project_xpto --entry-point=xpto --runtime=python39 --source=xpto --trigger-http --vpc-connector=redis --allow-unauthenticated 我已经尝试在命令中添加beta,但没有任何反应。

我的main.py 文件在下面

import json
import logging
from datetime import date
from http import HTTPStatus
from flask import Request
import service

setup_logger()
LOGGER = logging.getLogger(__name__)

def xpto(request: Request, token: str):
    LOGGER.info(f"{request.method} accepted.")

    id = get_id(token)

    res_xpto = get_xpto(id=id)

    return make_response(
        json.dumps(res_xpto, default=lambda t: str(t) if isinstance(t, date) else t),
        http_code=HTTPStatus.OK,
        headers={"Content-Type": "application/json"},
    )

奇怪的是,在尝试让它工作时,我只用下面的代码创建了一个新的 CF,并且相同的 gcloud 命令可以工作

def hello_world(request):
    return "Hello World"

编辑:

requirements.txt

--extra-index-url {URL}

cachetools==4.2.2; python_version >= "3.9" and python_version < "4.0"
certifi==2021.5.30; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.6.0"
cffi==1.14.6; python_version >= "3.9" and python_version < "4.0"
charset-normalizer==2.0.4; python_full_version >= "3.6.0" and python_version >= "3.9" and python_version < "4.0"
click==7.1.2; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
cloudevents==1.2.0
cryptography==3.4.8; python_version >= "3.9" and python_version < "4.0"
deprecation==2.1.0
flask==1.1.2; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
functions-framework==2.1.0; python_version >= "3.5" and python_version < "4"
google-api-core==2.0.1; python_version >= "3.9" and python_version < "4.0"
google-auth==2.0.2; python_version >= "3.9" and python_version < "4.0"
google-cloud-secret-manager==2.7.0; python_version >= "3.9" and python_version < "4.0"
googleapis-common-protos==1.53.0; python_version >= "3.9" and python_version < "4.0"
greenlet==1.1.1; python_version >= "3" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3"
grpc-google-iam-v1==0.12.3; python_version >= "3.9" and python_version < "4.0"
grpcio==1.39.0; python_version >= "3.9" and python_version < "4.0"
gunicorn==20.0.4; python_version >= "3.4"
idna==3.2; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_full_version >= "3.6.0" and python_version >= "3.9" and python_version < "4.0"
itsdangerous==1.1.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
jinja2==2.11.2; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
libcst==0.3.20; python_version >= "3.9" and python_version < "4.0"
markupsafe==1.1.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
mypy-extensions==0.4.3; python_version >= "3.9" and python_version < "4.0"
mysqlclient==2.0.3; python_version >= "3.5"
packaging==21.0; python_version >= "3.9" and python_version < "4.0"
pathtools==0.1.2
phpserialize==1.3
proto-plus==1.19.0; python_version >= "3.9" and python_version < "4.0"
protobuf==3.17.3; python_version >= "3.9" and python_version < "4.0"
pyasn1-modules==0.2.8; python_version >= "3.9" and python_version < "4.0"
pyasn1==0.4.8; python_version >= "3.9" and python_version < "4.0"
pycparser==2.20; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.4.0"
pydantic==1.8.2; python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.6.1"
pyjwt==2.1.0; python_version >= "3.9" and python_version < "4.0"
pyparsing==2.4.7; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.6"
pyyaml==5.4.1; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.6.0"
requests==2.26.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.6.0")
rsa==4.7.2; python_version >= "3.9" and python_version < "4"
six==1.16.0; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.3.0"
sqlalchemy==1.4.22; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.6.0")
tenacity==7.0.0
typing-extensions==3.10.0.2; python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.6.1"
typing-inspect==0.7.1; python_version >= "3.9" and python_version < "4.0"
urllib3==1.26.6; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_full_version >= "3.6.0" and python_version < "4" and python_version >= "3.9"
watchdog==1.0.2; python_version >= "3.6"
werkzeug==1.0.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")

【问题讨论】:

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


【解决方案1】:

可能是设置为CRLF换行符,可以使用dos2unix将脚本转成Unix格式

【讨论】:

  • 不,我已将所有内容更改为仅 LF,得到了同样的错误
猜你喜欢
  • 2019-01-30
  • 2017-08-15
  • 2021-02-26
  • 2018-09-14
  • 1970-01-01
  • 2020-05-21
  • 2019-08-30
  • 2022-09-23
  • 2019-10-28
相关资源
最近更新 更多