如何解决GCP PubSub订阅转移错误

时间:2020-05-03 15:23:36

标签: python google-cloud-platform cloud publish-subscribe subscription

我会在GCP上收到推特。我使用python语言。运行python代码时,出现此问题:
google.api_core.exceptions.NotFound:404找不到请求的项目或用户无权访问(project =我的第一个项目)。确保指定唯一的项目标识符 而不是Google Cloud Console的显示名称。

此处是代码

def receive_tweets(project, subscription_name):
subscriber = pubsub.SubscriberClient()
print("aaaaa")
subscription_path = subscriber.subscription_path(
    project, subscription_name)

def callback(message):
    print("aaa")
    print('Received message: {}'.format(message))
    collect_tweets(message.data)
    message.ack()

future = subscriber.subscribe(subscription_path, callback=callback)
print('Listening for messages on {}'.format(subscription_path))

try:
    future.result()  **---error this rows**
except Exception as e:
    print(
        'Listening for messages on {} threw an Exception: {}'.format(
            subscription_name, e))
    raise

while True:
    time.sleep(10)

0 个答案:

没有答案