GeezerVison is showing github.com — Homepage sample for pubsub does not work · Issue #6 · GoogleCloudPlatform/getting-started-python
Homepage sample for pubsub does not work #6Labels 🚨This issue needs some love.triage meI really want to be triaged. Activitydhermes commented on Sep 8, 2015 theacodes commented on Sep 10, 2015 This has been fixed. Closing, feel free to comment if you still have issues @jpvic jpvic commented on 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 commented on Sep 10, 2015 I'm not able to reproduce that, can you tell me your gcloud version and full python version? jpvic commented on 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: [email protected]
License: Apache 2.0 theacodes commented on Sep 10, 2015 Thanks, did you create a topic and subscription before running the sample? dhermes commented on 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 commented on Sep 10, 2015 jpvic commented on 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 commented on Sep 14, 2015 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 commented on 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 commented on Sep 14, 2015 dhermes commented on 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 commented on Sep 14, 2015 Done, and I couldn't reproduce it on my end. theacodes commented on Feb 19, 2016 These samples have been removed, so I'm closing this issue.
MetadataMetadata🚨This issue needs some love.triage meI really want to be triaged. DevelopmentNo branches or pull requestsIssue actions
|