I'm using google-cloud-pubsub in Django and the Google Cloud Pub/Sub Emulator. I'm trying to create a topic in this way:
publisher = pubsub.PublisherClient ()
topic_path = publisher.topic_path ('my-project', 'my-new-topic')
topic = publisher.create_topic (topic_path)
topic.publish (topic, request.data ['url']. encode ('utf-8'))
but it gives me this exception:
StatusCode.PERMISSION_DENIED, User not authorized to perform this action.
I'm wondering if there is anything else to configure except the PUBSUB_EMULATOR_HOST environment variable. Do I have to set some permissions, even for the emulator? The tutorial doesn't explain much more.
Thanks in advance.
4 years late :) but this should solve it:
Why
The command in google tutorial (
gcloud beta emulators pubsub env-init
) for some reason doesn't set the environment variable. So your pubsub apis call the service account instead of the local emulator which result in permission errors.Manually set it and verify it's set using
echo $PUBSUB_EMULATOR_HOST