I'm using the python standard environment and would like to publish a message to google pub/sub. However, it appears that the google cloud libraries are not included with the environment, at least without some sort of additional configuration.
from google.cloud import pubsub
ImportError: No module named cloud
This is running on a deployed instance. The example google gives for using pub/sub is in the flexible environment.
App Engine Standard's Python2.7 runtime does not support Pub/Sub Cloud Client Library, only Pub/Sub Service API Client Library. There's some new code samples that shows how to do that.
import googleapiclient.discovery
import base64
service = build('pubsub', 'v1')
topic_path = 'projects/{your_project_id}/topics/{your_topic}'
service.projects().topics().publish(
topic=topic_path, body={
"messages": [{
"data": base64.b64encode(data)
}]
}).execute()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.