Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    DbR
    DbR is offline
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Python Error with Bitcoin

    I'm trying to replicate what was done in this video: https://www.youtube.com/watch?v=cWf-WXaLFJ8

    I think he is using a different version of python though because I'm getting errors. I have python 3.4

    This is what I have so far:

    Code:
    import time
    import json
    import urllib.request
    
    def main():
        btcePrices = urllib.request.urlopen('https://btc-e.com/api/2/btc_usd/ticker')
        btcejson = json.loads(btcePrices)
        btcelastP = btcejson['ticker']['last']
        btcelastT = btcejson['ticker']['updated']
        print (btcelastP)
    
    while True:
        main()
        time.sleep(1)
    I am now getting an error that says TypeError: the JSON object must be str, not 'HTTPResponse'
    anyone know how to fix this?

  • #2
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi DbR:
    I changed a couple of things and got this to work.
    1. you left off the .read() method at the end of the first line in main()
    2. I used the simplejson library instead of json

    See code below:
    Code:
    import time
    import simplejson
    import urllib.request
    
    def main():
        btcePrices = urllib.request.urlopen('https://btc-e.com/api/2/btc_usd/ticker').read()
        btcejson = simplejson.loads(btcePrices)
        btcelastP = btcejson['ticker']['last']
        btcelastT = btcejson['ticker']['updated']
        print(btcelastP)
    
    while True:
        main()
        time.sleep(1)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •