Author

Topic: Python novice needs help and errorchecking [done] (Read 1533 times)

legendary
Activity: 2126
Merit: 1001
February 18, 2012, 11:51:02 AM
#7
Is there any reason you're not using the latest websocket-client version(0.5.1)? Running your script with the latest version I get 'Message:  4:::{"op":"remark","message":"Now online (no channels)"}' lines.

Huh?!?
I tried it several times, did some more changes to the code, have debug messages print out at several points, and suddenly messages came in? I would say I didnt change any substantial parts, but now it works. Maybe it really was the websocket-client version. Maybe I was unlucky enough to connect when the websocket daemon wasnt sending stuff. Maybe I didnt let the script run long enough. Whatever, I'll get me a a beer now, cheers! :-)

Ente

Hmpf.
I did not change the code since last time. Now I wont get any data any more. Its back ti heartbeats only again.
I will now connect new every minute and see if I eventually get data again.
So it seems that either the problem still exists, or the socket is totally unstable and only works randomly at best.

Do you guys receive data?

Ente
full member
Activity: 216
Merit: 100
So, need my Bitcoin address?
legendary
Activity: 2126
Merit: 1001
Is there any reason you're not using the latest websocket-client version(0.5.1)? Running your script with the latest version I get 'Message:  4:::{"op":"remark","message":"Now online (no channels)"}' lines.

Huh?!?
I tried it several times, did some more changes to the code, have debug messages print out at several points, and suddenly messages came in? I would say I didnt change any substantial parts, but now it works. Maybe it really was the websocket-client version. Maybe I was unlucky enough to connect when the websocket daemon wasnt sending stuff. Maybe I didnt let the script run long enough. Whatever, I'll get me a a beer now, cheers! :-)

Ente
legendary
Activity: 2126
Merit: 1001
Is there any reason you're not using the latest websocket-client version(0.5.1)? Running your script with the latest version I get 'Message:  4:::{"op":"remark","message":"Now online (no channels)"}' lines.

Lol now thats unexpected! I found out I use python 2.6.6 which shipped with my Debian, thats why I still have the old websocket-client version. Will see if it helps, thank you for the pointer!

Ente

Edit:
Switched to python 2.7.2, have websocket-client installed for 2.7 only. Still no joy, only heartbeats come in.
full member
Activity: 216
Merit: 100
Is there any reason you're not using the latest websocket-client version(0.5.1)? Running your script with the latest version I get 'Message:  4:::{"op":"remark","message":"Now online (no channels)"}' lines.
legendary
Activity: 2126
Merit: 1001
My first problem is from https://bitcointalksearch.org/topic/m.749200:

I try to connect to MtGox via socket.io. I get the connection-id fine, and am able to connect to the websocket too. I then receive heartbeats, which I answer, and continue to receive.

I receive no other data. Things I send have no effect. Just heartbeats, nothing else.
This code is heavily stripped. The full script worked some weeks ago, using these lines.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from websocket import create_connection
import urllib
import re
import time

try:
    import json
except ImportError:
    import simplejson as json


wsurl = "wss://socketio.mtgox.com/socket.io/"
iourl = "https://socketio.mtgox.com/socket.io/"

############

print "Connecting to socket.io.."
url = iourl + "1"
f = urllib.urlopen(url)
output = f.read()
f.close()
ausgabe = re.search('[0-9]+', output, 0)
sessionid = ausgabe.group()

print "New websocket url:"
wssurl = wsurl + "1" + "/websocket/" + sessionid
print wssurl

############

print "Connecting to websocket..\n"

socket = create_connection(wssurl)

while 1:
  echo =  socket.recv()
  if "1::" in echo:
    print "Heartbeat 1"
    socket.send("1::")
  elif "2::" in echo:
    print "Heartbeat 2"
    socket.send("2::")
  else:
    print "Message: ",echo
  time.sleep(2)
      

The websocket client I use here is from http://pypi.python.org/pypi/websocket-client/0.4.
The whole script dies eventually, from having stripped all error-handling.
If you like to see the whole script, let me know.

I pledge 1 Bitcoin to the first answer to solve this problem.
You are welcome to use PMs or post right here.

Ente

edit: typo which sent '1::' in both types of heartbeats.
legendary
Activity: 2126
Merit: 1001
Hello fellow coders,

I try to write my own MtGox bot. I am no programmer, I am basically learning-by-doing python with this project. Beginning at almost zero, going step-by-step with help google. So you will need a bit of patience with me ;-)

I will probably have new issues from time to time and will post in this thread when I need more help.

This is the first time I try this approach. So for starters, I bid one Bitcoin to the (first) person which solves my problem.
Do you suggest a different approach? Sharing the pledge between several helpers, for example? Or a higher, or lower pledge? The more expensive this gets, the less I will use it and the more I will try to solve obstacles by myself.

Lets see how this turns out?

Ente
Jump to: