Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubsub publisher.py throws error "unexpected keyword argument 'data'" #1880

Closed
sivadotblog opened this issue Nov 30, 2018 · 2 comments
Closed
Labels

Comments

@sivadotblog
Copy link

sivadotblog commented Nov 30, 2018

I am trying to execute the file https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/pubsub/cloud-client/publisher.py

I modified the script in my local machine to include Service Account and that is the only change.
publisher = pubsub_v1.PublisherClient.from_service_account_json("<json key>")

This is what I get when i execute:

python publisher.py siva-poc publish "projects/siva-poc/topics/sample_topic"
Traceback (most recent call last):
File "publisher.py", line 275, in
publish_messages(publisher,args.project_id, args.topic_name)
File "publisher.py", line 93, in publish_messages
future = publisher.publish(topic_path, data=data)
TypeError: publish() got an unexpected keyword argument 'data'

I tried a different operation "publish-with-custom-attributes" but it still complains:

python publisher.py siva-poc publish-with-custom-attributes "projects/siva-poc/topics/sample_topic"
Traceback (most recent call last):
File "publisher.py", line 278, in
args.project_id, args.topic_name)
File "publisher.py", line 125, in publish_messages_with_custom_attributes
topic_path, data, origin='python-sample', username='gcp')
TypeError: publish() got an unexpected keyword argument 'origin'

I am not sure why is it complaining about the argument in the publisher_client.

Could someone help me with this, please?

@sivadotblog
Copy link
Author

sivadotblog commented Nov 30, 2018

I got some insights from a different post to fix this. There is an issue with the way we pass service account. pubsub_v1.PublisherClient.from_service_account_json("<json key>")

I tried a different approach and that worked.
credentials = service_account.Credentials.from_service_account_file("<json key>") publisher = pubsub_v1.PublisherClient(credentials=credentials)
But I believe PublisherClient still needs to be fixed.

@engelke engelke added the Fixit label Dec 6, 2018
@engelke
Copy link
Contributor

engelke commented Dec 6, 2018

It appears it has been fixed by PR googleapis/google-cloud-python#6666 just 8 days ago. It should be available via pip install soon. Thanks for the report - it led to this fix!

@engelke engelke closed this as completed Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants