Google云功能-Python部署失败-部署失败:函数在加载用户代码时失败

我正在尝试使用内联编辑器重新部署以前运行的Python云功能。如果未更改source或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

因此问题已解决。

pianyuan 回答:Google云功能-Python部署失败-部署失败:函数在加载用户代码时失败

如Dustin所述,如果您共享功能的代码和 requirements.txt 文件的内容,这将很有帮助。

基于该错误(没有更具体的信息),在我看来,问题出在您的Cloud Functions配置上。在这种情况下,可以重置云功能的配置,但是,还需要删除功能。您可以通过执行以下操作来实现它:

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

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

,

使用mysql-connector-python 解决

感谢您的帮助和建议。

本文链接:https://www.f2er.com/3165245.html

大家都在问