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

Homepage sample for pubsub does not work #6

Closed
theacodes opened this issue Sep 8, 2015 · 15 comments
Closed

Homepage sample for pubsub does not work #6

theacodes opened this issue Sep 8, 2015 · 15 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@theacodes
Copy link

Original issue

@theacodes theacodes self-assigned this Sep 8, 2015
@dhermes
Copy link

dhermes commented Sep 8, 2015

/cc @jpvic

@theacodes
Copy link
Author

This has been fixed. Closing, feel free to comment if you still have issues @jpvic

@jpvic
Copy link

jpvic commented Sep 10, 2015

The typo is corrected.

from gcloud import pubsub

client = pubsub.Client(project='your-project-id')
topic = client.topic('your-topic-name')

topic.publish('Ping!')

subscription = topic.subscription('your-subscription-name')

messages = subscription.pull()

for ackid, message in messages:
    print message.data

subscription.acknowledge([ackid for ackid, _ in messages])

the examples ends with the same error:

  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

@theacodes
Copy link
Author

I'm not able to reproduce that, can you tell me your gcloud version and full python version?

@jpvic
Copy link

jpvic commented Sep 10, 2015

python -c 'import sys; print(sys.version)'

2.7.10 (default, Jul 5 2015, 14:15:43)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)]

pip show gcloud


Metadata-Version: 1.1
Name: gcloud
Version: 0.7.1
Summary: API Client library for Google Cloud
Home-page: https://github.com/GoogleCloudPlatform/gcloud-python
Author: Google Cloud Platform
Author-email: jjg+gcloud-python@google.com
License: Apache 2.0

@theacodes
Copy link
Author

Thanks, did you create a topic and subscription before running the sample?

@dhermes
Copy link

dhermes commented Sep 10, 2015

It seems we could do a better job catching the error instead of trying to json decode something that is invalid. @jpvic Could you provide the whole stack trace?

If you could, use triple backticks to format the stacktrace (easier on the eyes). Or @jonparrott could edit your post to add the formatting.

@theacodes
Copy link
Author

edited.

@jpvic
Copy link

jpvic commented Sep 10, 2015

indeed. I used the topic and subscription of my project. I do use the messaging platform with no problems in the project.
In my project I use httplib2.http() .... and that works.
But the easy code proposed with the same topic and subscription doesn't work.

@theacodes
Copy link
Author

Can you try with a new topic/subscription? The subscription should be pull subscription. You can create them with these gcloud commands:

$ gcloud alpha pubsub topics create [your-topic-name]
$ gcloud alpha pubsub subcriptions create [your-subscription-name] --topic [your-topic-name] 

@jpvic
Copy link

jpvic commented Sep 14, 2015

I didn't created the original topic with gcloud command

I retried with with the proposed command : ( watch out typo 'subcriptions' ==> subscriptions )

from gcloud import pubsub
import errno

client = pubsub.Client(project='demoproject')
topic = client.topic('projects/demoproject/topics/demotopic')

try:
    topic.publish('Ping!')
except errno as e:
    print(e)

subscription = topic.subscription('projects/demoproject/subscriptions/demosubscription')

messages = subscription.pull()

for ackid, message in messages:
    print message.data

subscription.acknowledge([ackid for ackid, _ in messages])

same result 👍

/usr/bin/python2.7 /root/PycharmProjects/github/pythonCloudExample.py
Traceback (most recent call last):
  File "/root/PycharmProjects/github/pythonCloudExample.py", line 8, in <module>
    topic.publish('Ping!')
  File "/usr/lib/python2.7/site-packages/gcloud-0.7.1-py2.7.egg/gcloud/pubsub/topic.py", line 186, in publish
    method='POST', path='%s:publish' % (self.path,), data=data)
  File "/usr/lib/python2.7/site-packages/gcloud-0.7.1-py2.7.egg/gcloud/connection.py", line 419, in api_request
    error_info=method + ' ' + url)
  File "/usr/lib/python2.7/site-packages/gcloud-0.7.1-py2.7.egg/gcloud/exceptions.py", line 185, in make_exception
    payload = json.loads(content)
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Process finished with exit code 1

@theacodes
Copy link
Author

@dhermes any ideas?

@dhermes
Copy link

dhermes commented Sep 14, 2015

@jonparrott Can you format the above stacktrace with triple quotes (I don't have edit privileges)?

Yes, I think the error payload is HTML only, we have a flag use_json=True which is only used for the discovery-based APIs.

It's possible here that his payload is a more generic error, I'd need a debugger to actually find out, but I can try to reproduce myself as well (pending the code formatting 😄)

@theacodes
Copy link
Author

Done, and I couldn't reproduce it on my end.

@theacodes
Copy link
Author

These samples have been removed, so I'm closing this issue.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants