1

I am trying to create a subscription to a topic using Google's pubsub_v1 library in python. I have successfully created a topic using the library (I can see it in the cloud console after creation). However I am having an issue trying to create a subscription. I tried to solution given in this question to no avail. Here is my subscription code:

from google.cloud import pubsub_v1 as pubsub

topic_name = 'logs'
sub_name = 'logs-consumer'
project_name = 'my-project' # valid project name

subscriber = pubsub.SubscriberClient()
topic_path = subscriber.topic_path(project_name, topic_name)
subscription_path = subscriber.subscription_path(project_name, sub_name)

# Wrap the subscriber in a 'with' block to automatically call close() to
# close the underlying gRPC channel when done.
with subscriber:

    subscription = subscriber.create_subscription(
        request={"name": subscription_path, "topic": topic_path}
    )

Whenever I run this code, I get the following error:

Traceback (most recent call last):
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/grpc/_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "Project 'project:gcp-python-291817' not found or deleted."
    debug_error_string = "{"created":"@1607133732.705528000","description":"Error received from peer ipv6:[2607:f8b0:400f:801::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"Project 'project:gcp-python-291817' not found or deleted.","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "logger_consumer_GCP.py", line 28, in <module>
    request={"name": subscription_path, "topic": topic_path}
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/cloud/pubsub_v1/_gapic.py", line 40, in <lambda>
    fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw)  # noqa
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/pubsub_v1/services/subscriber/client.py", line 526, in create_subscription
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
    on_error=on_error,
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/Users/zacharymcgrath/Library/Python/3.7/lib/python/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 Project 'project:gcp-python-291817' not found or deleted.

I thought it might be that my project gcloud variable had somehow changed and the library uses environment variables, but I double checked and it was correct. I'm not really sure what I'm doing thats different than the question referred to above. Thanks.

Update

Some helpful information from the comments:

  • gcp-python-291817 is not the name of the project
  • the project name is in a config file that both the publisher and the subscriber read from. The publisher did not have any problems when reading the project name from the file and publishing a message
  • I had a ssh configuration for a VM instance within this project named gcp-python, but was removed a while ago
  • clearing the gcloud cache and gsutils cache has not fixed the problem either
Zach
  • 93
  • 1
  • 11
  • Project `gcp-python-291817` does not exist or maybe you do not have IAM roles (permission) to access it. – John Hanley Dec 05 '20 at 02:59
  • For reference `gcp-python-291817` isn't the name of the project – Zach Dec 05 '20 at 03:11
  • Whatever it is called, you are incorrectly naming the project. – John Hanley Dec 05 '20 at 03:41
  • If you look at the comment by @DazWilkin below, I printed out the full path of the topic and the subscription and the correct project name is in the string. The project name is in a config file. Both the publisher and subscriber files read from this and the publisher had no problem – Zach Dec 05 '20 at 03:46
  • Where in your question are those details. Start with these links: https://stackoverflow.com/help/minimal-reproducible-example AND https://stackoverflow.com/help/how-to-ask – John Hanley Dec 05 '20 at 03:59

1 Answers1

2

I found the issue. I re-ran

gcloud auth application-default login  

and made sure that GOOGLE_APPLICATION_CREDENTIALS was pointed to the new credentials json file and it worked. I must have messed up the credentials file at some point. Thanks for the help!

Zach
  • 93
  • 1
  • 11
  • Hello! Thank you for adding an answer, please remember that you can mark your answer as correct. https://stackoverflow.com/help/self-answer – Juancki Dec 07 '20 at 10:22