Python 如何从Google Pub/Sub获取objectId、bucketId等

Python 如何从Google Pub/Sub获取objectId、bucketId等,python,google-cloud-platform,google-cloud-pubsub,Python,Google Cloud Platform,Google Cloud Pubsub,我使用的是一个Pub/Sub主题,当在GCS bucket中创建一个对象时会触发它。以下是我目前掌握的代码: @app.route('/', methods=["POST"]) def index(): envelope = request.get_json() myfunc(envelope) return "", 204 def myfunc(envelope): event_type = envelope.ge

我使用的是一个Pub/Sub主题,当在GCS bucket中创建一个对象时会触发它。以下是我目前掌握的代码:

@app.route('/', methods=["POST"])
def index():

    envelope = request.get_json()
    myfunc(envelope)

    return "", 204


def myfunc(envelope):
    event_type = envelope.get("eventType")
    bucket_id = envelope.get("bucketId")
    object_id = envelope.get("objectId")
    
    print(event_type)
    print(bucket_id)
    print(object_id)
目前,这只是为每次打印打印输出
'None'
。我想让它打印与
objectId
bucketId
etc键相关的值,这样我就能够获得出现在GCS bucket中的文件名


谢谢你的帮助

我不确定。。。。但是我猜你函数的签名是不正确的


当您使用推送订阅时,您会收到一条JSON格式的POST正文中的PubSub消息。该消息的架构与

是否应将
信封作为该消息?如果是这样,这个github示例应该可以帮助您正确解析消息。上面的例子显示了事件类型、Bucket ID、Object ID和每当在连接到发布/订阅主题的Bucket上创建对象时的生成。是的,在某种程度上它肯定是错误的。但该链接是在对象最终确定时用于触发器的,而不是pubsub触发器。我需要后者,因为我需要能够nack/ack消息。如果您有“推送”pubsub订阅(云功能由消息触发),据我所知,您将无法从代码内部确认消息。。。