Skip to content

Pubsub example on front page fails if topic does not already exist #1082

Description

@Michael0x2a

The pubsub example throws an exception if the specified topic does not already exist. Example:

>>>fromgcloudimportpubsub>>>client=pubsub.Client(project=MY_PROJECT_ID)
>>>topic=client.topic('my-new-custom-topic')
>>>topic.publish('Ping!')
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/usr/local/lib/python2.7/dist-packages/gcloud/pubsub/topic.py", line186, inpublishmethod='POST', path='%s:publish'% (self.path,), data=data)
File"/usr/local/lib/python2.7/dist-packages/gcloud/connection.py", line419, inapi_requesterror_info=method+' '+url)
gcloud.exceptions.NotFound: 404Resourcenotfound (resource=my-custom-topic). (POSThttps://pubsub.googleapis.com/v1/projects/lee-cloud/topics/my-custom-topic:publish)

The code sample will resume working if you create the topic and re-run the sample, but it would be nice if the code sample included a line or two demonstrating how to create a topic if it doesn't exist.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions