【问题标题】:Google Cloud Functions - Python deployment failing - Deployment failure: Function failed on loading user codeGoogle Cloud Functions - Python 部署失败 - 部署失败:加载用户代码时函数失败
【发布时间】:2019-11-04 16:27:51
【问题描述】:

我正在尝试使用内联编辑器重新部署以前工作的 Python 云函数。在源或 requirements.txt 没有更改的情况下,部署失败并显示以下错误消息:

Deployment failure:
Function failed on loading user code. Error message: Error: cannot communicate with function.

功能日志提供以下详细信息:

{
 insertId: "-xueafgcygm"  
 logName: "projects/xxx/logs/cloudaudit.googleapis.com%2Factivity"  
 operation: {
  id: "operations/YXBvdGV4MzYwL3VzLWNlbnRyYWwxL2RvTG9hZEFwb3RleDM2MFByb2R1Y3QvSHhiWWlvVHVmdkE"   
  last: true   
  producer: "cloudfunctions.googleapis.com"   
 }
 protoPayload: {
  @type: "type.googleapis.com/google.cloud.audit.AuditLog"   
  authenticationInfo: {
   principalEmail: "xxx@gmail.com"    
  }
  methodName: "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction"   
  requestMetadata: {
   destinationAttributes: {
   }
   requestAttributes: {
   }
  }
  resourceName: "projects/xxx/locations/us-central1/functions/doLoadProduct"   
  serviceName: "cloudfunctions.googleapis.com"   
  status: {
   code: 3    
   message: "INVALID_ARGUMENT"    
  }
 }
 receiveTimestamp: "2019-11-04T16:17:00.108301794Z"  
 resource: {
  labels: {
   function_name: "doLoadProduct"    
   project_id: "xxx"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "ERROR"  
 timestamp: "2019-11-04T16:16:59.612Z"  
}

这从上周五开始,一直持续到今天。我还尝试使用 gcloud 函数 deploy 进行本地部署,但我收到了类似的错误消息:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Error: cannot communicate with function.

我希望为解决此问题的后续步骤提供一些指导。

--- 更新---

根据 Dustin 提供源文件和需求文件的建议,我努力查看是否可以用尽可能少的代码重新创建问题。

main.py

import base64
import mysql.connector as db
from google.cloud import storage

def hello_pubsub(event, context):
    pubsub_message = base64.b64decode(event['data']).decode('utf-8')
    print(pubsub_message)

requirements.txt

google-cloud-storage==1.21.0
mysql-connector-python==8.0.18

原来google-cloud-storage的版本不兼容。改成mysql-connector-phthon

所以问题解决了。

【问题讨论】:

  • 你能把你的函数和requirements.txt包括进来吗?
  • Cloud Functions 服务帐户是否有任何更改?这可能是暂时性错误。几个小时后重试。

标签: python-3.x google-cloud-platform google-cloud-functions


【解决方案1】:

正如 Dustin 所说,如果您分享您的 函数 的代码和 requirements.txt 文件的内容将会很有帮助。

根据错误(没有更具体的信息),在我看来问题出在您的 Cloud Functions 配置中。如果是这种情况,它可能有助于重置云函数的配置,但也需要删除您的函数。您可以通过以下方式实现:

  • 转到 Google Cloud Console -> API 和服务 -> Cloud Functions API -> 禁用 API
  • 禁用 Google Cloud Functions API。
  • 再次启用 API。
  • 尝试部署该功能。

如果有帮助或提供更多详细信息,请告诉我,以便我更深入地研究它。

【讨论】:

    【解决方案2】:

    使用mysql-connector-python解决

    感谢您的帮助和建议。

    【讨论】:

      猜你喜欢
      • 2020-11-03
      • 2021-11-22
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      相关资源
      最近更新 更多