7

I'm trying to create an application in Python that powers a GPIO port when the balance of a Dogecoin address changes. I'm using the websocket API here and this websocket client.

My code looks like this:

from websocket import create_connection
ws = create_connection("wss://ws.dogechain.info/inv")
ws.send("op":"addr_sub", "addr":"dogecoin_address")
result =  ws.recv()
print (result)
ws.close()

It's obviously not the final code, but I just wanted to see if I'm even able to connect to the websocket and get any kind of response. When I run that code, it throws errors because of the colons in the request. I don't know what way I should format it that it won't throw an error.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
iSasFTW
  • 165
  • 2
  • 3
  • 8

1 Answers1

12

I'm guessing that the API wants JSON data. You can get that like so:

import json
from websocket import create_connection
ws = create_connection("wss://ws.dogechain.info/inv")
ws.send(json.dumps({"op":"addr_sub", "addr":"dogecoin_address"}))
result =  ws.recv()
print (result)
ws.close()
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • It worked! Now i have another problem though... I get an error saying something about SSL certificate verification failure. Maybe i'll try the ws:// instead of wss:// if that works... EDIT: Nope, now it jut freezes up! – iSasFTW Dec 08 '16 at 20:35
  • If this solves your (asked) problem you should go ahead and accept it. It may be worthwhile asking another question (though you might want to re-read [how to ask](http://stackoverflow.com/help/how-to-ask) to see what makes for a good question) when it comes to the SSL issue. – Wayne Werner Dec 08 '16 at 22:11
  • There's probably just some issue with the SSL certificates that you have installed... or maybe just *their* ssl cert :P – Wayne Werner Dec 08 '16 at 22:12