Bitcoin Forum
December 08, 2016, 10:11:31 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Python novice needs help and errorchecking [done]  (Read 1380 times)
Ente
Legendary
*
Offline Offline

Activity: 1834



View Profile
February 15, 2012, 08:42:27 AM
 #1

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
1481191891
Hero Member
*
Offline Offline

Posts: 1481191891

View Profile Personal Message (Offline)

Ignore
1481191891
Reply with quote  #2

1481191891
Report to moderator
1481191891
Hero Member
*
Offline Offline

Posts: 1481191891

View Profile Personal Message (Offline)

Ignore
1481191891
Reply with quote  #2

1481191891
Report to moderator
1481191891
Hero Member
*
Offline Offline

Posts: 1481191891

View Profile Personal Message (Offline)

Ignore
1481191891
Reply with quote  #2

1481191891
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481191891
Hero Member
*
Offline Offline

Posts: 1481191891

View Profile Personal Message (Offline)

Ignore
1481191891
Reply with quote  #2

1481191891
Report to moderator
Ente
Legendary
*
Offline Offline

Activity: 1834



View Profile
February 15, 2012, 08:47:44 AM
 #2

My first problem is from https://bitcointalk.org/index.php?topic=5855.msg749200#msg749200:

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.
TurdHurdur
Full Member
***
Offline Offline

Activity: 217


View Profile
February 18, 2012, 03:05:56 AM
 #3

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.
Ente
Legendary
*
Offline Offline

Activity: 1834



View Profile
February 18, 2012, 12:24:22 PM
 #4

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.
Ente
Legendary
*
Offline Offline

Activity: 1834



View Profile
February 18, 2012, 01:36:39 PM
 #5

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
TurdHurdur
Full Member
***
Offline Offline

Activity: 217


View Profile
February 18, 2012, 01:53:51 PM
 #6

So, need my Bitcoin address?
Ente
Legendary
*
Offline Offline

Activity: 1834



View Profile
February 18, 2012, 03:51:02 PM
 #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
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!