title: How can I get the python pubsub tutorial up and running?
body: <p>I am going through this, what should be a simple/straightforward <a href="https://cloud.google.com/pubsub/docs/quickstart-py-mac" rel="nofollow noreferrer">tutorial</a> on the GCP website, to get started on PubSub. I am working on 10.14.5, using the python environment as suggested by the tutorial. Below is the code for <code>pub.py</code>. (Code for and <code>sub.py</code> are identical to that in the tutorial.)</p>
  
  <p><strong>pub.py</strong></p>
  
  <pre><code>#!/usr/bin/env python
  
  # [START pubsub_quickstart_pub_all]
  import argparse,os
  import time
  # [START pubsub_quickstart_pub_deps]
  from google.cloud import pubsub_v1
  # [END pubsub_quickstart_pub_deps]
  
  
  def get_callback(api_future, data):
      """Wrap message data in the context of the callback function."""
  
      def callback(api_future):
          try:
              print("Published message {} now has message ID {}".format(
                  data, api_future.result()))
          except Exception:
              print("A problem occurred when publishing {}: {}\n".format(
                  data, api_future.exception()))
              raise
      return callback
  
  
  def pub(project_id, topic_name):
      """Publishes a message to a Pub/Sub topic."""
      # [START pubsub_quickstart_pub_client]
      # Initialize a Publisher client
      client = pubsub_v1.PublisherClient()
      # [END pubsub_quickstart_pub_client]
      # Create a fully qualified identifier in the form of
      # `projects/{project_id}/topics/{topic_name}`
      topic_path = client.topic_path(project_id, topic_name)
  
      # Data sent to Cloud Pub/Sub must be a bytestring
      data = b"Hello, World!"
  
      # When you publish a message, the client returns a future.
      api_future = client.publish(topic_path, data=data)
      api_future.add_done_callback(get_callback(api_future, data))
  
      print("topic path:" + topic_path)
      print("GOOGLE_APPLICATION_CREDENTIALS:" + os.environ['GOOGLE_APPLICATION_CREDENTIALS'])
      # Keep the main thread from exiting until background message
      # is processed.
      while api_future.running():
          time.sleep(0.1)
  
  
  if __name__ == '__main__':
      parser = argparse.ArgumentParser(
          description=__doc__,
          formatter_class=argparse.RawDescriptionHelpFormatter
      )
      parser.add_argument('project_id', help='Google Cloud project ID')
      parser.add_argument('topic_name', help='Pub/Sub topic name')
  
      args = parser.parse_args()
  
      pub(args.project_id, args.topic_name)
  # [END pubsub_quickstart_pub_all]
  
  </code></pre>
  
  <p>However, when I run this: </p>
  
  <p><code>python pub.py $PROJECT hello_topic</code></p>
  
  <p>script, I do not get the expected behaviour. I am expecting this command to say that a message has been published, and that the subscriber command (invoked by <code>python sub.py $PROJECT sub_one</code> on another terminal), should say that a message have been received.</p>
  
  <p>Furthermore, when I run <code>pub.py</code>, and examine the console here:</p>
  
  <p><a href="https://console.cloud.google.com/cloudpubsub/topic/detail/hello_topic?project=MYPROJECT" rel="nofollow noreferrer">https://console.cloud.google.com/cloudpubsub/topic/detail/hello_topic?project=MYPROJECT</a></p>
  
  <p>The <code>Publish Message Count</code> indicates that no messages seem to have been published by the client.</p>
  
  <p>I am fairly confident the set up is ok, since:</p>
  
  <pre><code>$ gcloud pubsub topics list
  name: projects/&lt;MYPROJECT&gt;/topics/hello_topic
  
  $ gcloud pubsub topics list-subscriptions hello_topic
  ---
    projects/&lt;MYPROJECT&gt;/subscriptions/sub_two
  ---
    projects/&lt;MYPROJECT&gt;/subscriptions/sub_one
  </code></pre>
  
  <p>Also, sending messages directly using the <code>gcloud</code> utility, also gives expected results.</p>
  
  <pre><code>$ gcloud pubsub topics publish hello_topic --message "test message 123"
  messageIds:
  - '709682720030464'
  
  $ gcloud pubsub subscriptions pull --auto-ack one_sub
  ┌──────────────────┬─────────────────┬────────────┐
  │       DATA       │    MESSAGE_ID   │ ATTRIBUTES │
  ├──────────────────┼─────────────────┼────────────┤
  │ test message 123 │ 709682720030464 │            │
  └──────────────────┴─────────────────┴────────────┘
  </code></pre>
  
  <p>I also believe that the credentials have been set up correctly, although I am unsure how to verify this.</p>
  
  <p>Could someone please provide pointers on what else I should check/verify to get the expected behaviour?</p>