google-cloud-python: PubSub: AttributeError: 'Client' object has no attribute 'pull'
-
Specify the API at the beginning of the title (for example, “BigQuery: …”) General, Core, and Other are also allowed as types
Pub/Sub -
OS type and version
Windows 10 -
Python version and virtual environment information
python --versionPython 2.7.13 -
google-cloud-python version
pip show google-cloud,pip show google-<service>orpip 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
- Stacktrace if available
AttributeError: 'Client' object has no attribute 'pull'
- 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
- 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)
@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.
Related documentation: https://grpc.io/blog/pubsub
Example documentation that’s either incomplete or sample code has typos https://googlecloudplatform.github.io/google-cloud-python/latest/pubsub/publisher/api/client.html
Some places topic_path is constructed like this
Other places like this:
While they’re both valid approaches, it’s not how a library documentation explains the supported types, formats and utility libraries
I hope this info helps
@lukesneeringer why was
pullremoved? 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.0and 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-coreandgoogle-api-core.@lukesneeringer
from google.cloud.pubsub_v1.gapic.subscriber_client import SubscriberClientdoesn’t exist on pubsub 2.9.0. It should befrom google.cloud.gapic.pubsub.v1.subscriber_client import SubscriberClient