GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #6

New issue
Copy link
New issue
Copy link
Closed
Closed
Homepage sample for pubsub does not work#6
Copy link
Assignees
theacodes
Labels
🚨This issue needs some love.triage meI really want to be triaged.

Description

@theacodes
theacodes
opened on Sep 8, 2015
Issue body actions

Original issue

Activity

  1. theacodes
    self-assigned this
    on Sep 8, 2015
  2. dhermes commented on Sep 8, 2015

    @dhermes
    dhermes
    on Sep 8, 2015
    More actions

    /cc @jpvic

  3. theacodes commented on Sep 10, 2015

    @theacodes
    theacodes
    on Sep 10, 2015
    Author
    More actions

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

  4. jpvic commented on Sep 10, 2015

    @jpvic
    jpvic
    on Sep 10, 2015
    More actions

    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
    
  5. theacodes commented on Sep 10, 2015

    @theacodes
    theacodes
    on Sep 10, 2015
    Author
    More actions

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

  6. jpvic commented on Sep 10, 2015

    @jpvic
    jpvic
    on Sep 10, 2015
    More actions

    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

  7. theacodes commented on Sep 10, 2015

    @theacodes
    theacodes
    on Sep 10, 2015
    Author
    More actions

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

  8. dhermes commented on Sep 10, 2015

    @dhermes
    dhermes
    on Sep 10, 2015
    More actions

    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.

  9. theacodes commented on Sep 10, 2015

    @theacodes
    theacodes
    on Sep 10, 2015
    Author
    More actions

    edited.

  10. jpvic commented on Sep 10, 2015

    @jpvic
    jpvic
    on Sep 10, 2015
    More actions

    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.

  11. theacodes commented on Sep 14, 2015

    @theacodes
    theacodes
    on Sep 14, 2015
    Author
    More actions

    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] 
    
  12. jpvic commented on Sep 14, 2015

    @jpvic
    jpvic
    on Sep 14, 2015
    More actions

    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
    
    
  13. theacodes commented on Sep 14, 2015

    @theacodes
    theacodes
    on Sep 14, 2015
    Author
    More actions

    @dhermes any ideas?

  14. dhermes commented on Sep 14, 2015

    @dhermes
    dhermes
    on Sep 14, 2015
    More actions

    @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 😄)

  15. theacodes commented on Sep 14, 2015

    @theacodes
    theacodes
    on Sep 14, 2015
    Author
    More actions

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

  16. theacodes commented on Feb 19, 2016

    @theacodes
    theacodes
    on Feb 19, 2016
    Author
    More actions

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

  17. theacodes
    closed this as completedon Feb 19, 2016
  18. yoshi-automation
    added
    triage meI really want to be triaged.
    🚨This issue needs some love.
    on Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @theacodes
    theacodes

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.