I'm unable to create Pub/Sub Publisher Client using .json file (instead using implicit Application Default / GOOGLE_APPLICATION_CREDENTIALS env var). Is something wrong I'm doing or does Pub/Sub has some nuances ? in which case why so...?
Most Google Client Libraries allow this, for ex BigQuery
client = bigquery.Client.from_service_account_json(json_credentials_path = ‘PATH/service_account.json')
Digging through PubSub Client Library code, I tried to do same with Pub/Sub Client Library:
from google.cloud.pubsub_v1.gapic.publisher_client import PublisherClient
publisher = PublisherClient.from_service_account_file(filename='PATH/service_account.json')
And get the following error:
Traceback (most recent call last): File "", line 1, in
File “/[VIRT_ENV_PATH]/lib/python3.6/site-packages/google/cloud/pubsub_v1/gapic/publisher_client.py", line 78, in from_service_account_file return cls(*args, **kwargs)
File "/[VIRT_ENV_PATH]/lib/python3.6/site-packages/google/cloud/pubsub_v1/gapic/publisher_client.py", line 167, in init self.iam_policy_stub = (iam_policy_pb2.IAMPolicyStub(channel))
File "/[VIRT_ENV_PATH]/lib/python3.6/site-packages/google/iam/v1/iam_policy_pb2.py", line 344, in init self.SetIamPolicy = channel.unary_unary( AttributeError: 'NoneType' object has no attribute 'unary_unary'
If I want to use key .json file, I could only make it work using workaround,
cred = `service_account.Credentials.from_service_account_file(filename = 'PATH/service_account.json')
publisher = pubsub_v1.PublisherClient(credentials = cred)
Thanks in advance for giving me.