google-cloud-python: PubSub: AttributeError: 'Client' object has no attribute 'pull'

  1. Specify the API at the beginning of the title (for example, “BigQuery: …”) General, Core, and Other are also allowed as types Pub/Sub

  2. OS type and version Windows 10

  3. Python version and virtual environment information python --version Python 2.7.13

  4. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze

Name: google-cloud-pubsub
Version: 0.29.0
Summary: Python Client for Google Cloud Pub/Sub
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: c:\git\repo\venv\lib\site-packages
Requires: google-api-core, google-gax, psutil, grpc-google-iam-v1, google-cloud-core
  1. Stacktrace if available
AttributeError: 'Client' object has no attribute 'pull'
  1. Steps to reproduce
import mypubsub
mypubsub.create_topic("test-topic")
mypubsub.create_subscription("test-sub", "test-topic")
messages = mypubsub.pull_messages("test-sub")

Note: mypubsub is a helper library that wraps pubsub. Check code below

  1. Code example
from google.cloud import pubsub

def pull_messages(subscription_name, max_messages=999, return_immediately=True):
    """Query messages from subscription."""
    try:
        if not subscription_name:
            return None

        client = pubsub.SubscriberClient()
        subscription_path = client .subscription_path(os.getenv('GOOGLE_CLOUD_PROJECT'),
                                                         subscription_name)

        return client .pull(subscription_path, max_messages, return_immediately)
     except Exception as e:
        logging.exception("Google pub/sub pull messages")

    return None

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

@lukesneeringer Re: pull, I have no issue switching to async approach, I was just shooting in the dark while I’m attempting to migrate my library from pubsub 2.7.x to 2.8+ . Thank you for the workaround, I’ll try not to use it.

Re: documentation. I’m not an expert on how to organize documentation but as a consumer of that info I find it hard to figure out the right information. So since I don’t have a specific solution that I can recommend right now, let me share some of my struggles and hopefully when combined with other developers feedback you can have a better idea for a solution.

  1. There are lots of different locations for the same or similar documentation without a clear ability to know which version of the library it applies to. Here are some examples:

Related documentation: https://grpc.io/blog/pubsub

  1. Some of the code snippets and instructions are incomplete. Also, some code snippets won’t even run, the variable names are wrong. Example:
topic = 'projects/{project_id}/topics/{topic}'.format(project_id=os.getenv('GOOGLE_CLOUD_PROJECT'), topic='MY_TOPIC_NAME')

Other places like this:

topic= subscriber.topic_path(project, topic_name)

While they’re both valid approaches, it’s not how a library documentation explains the supported types, formats and utility libraries

  1. Some documentation leads to 404 pages and there are a bunch of github issues and threads on compilation errors or documentation moved. Example: Here’s a 404 documentation link: https://googlecloudplatform.github.io/google-cloud-python/latest/pubsub/usage.html and it’s referenced from official github repo: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/pubsub image

I hope this info helps

@lukesneeringer why was pull removed? We can see the the code is still there but specifically blacklisted - @_gapic.add_methods(subscriber_client.SubscriberClient, blacklist=('pull', 'streaming_pull'))

We have a lot of code thats based on synchroneous pulling which would be hard to convert. This also means we’re stuck in 0.27.0 and can’t upgrade any other Google dependency because of the shared dependencies all libraries have.

Good deal. We (hope) to be in a state of stability in google-cloud-core and google-api-core.

@lukesneeringer from google.cloud.pubsub_v1.gapic.subscriber_client import SubscriberClient doesn’t exist on pubsub 2.9.0. It should be from google.cloud.gapic.pubsub.v1.subscriber_client import SubscriberClient