How do I get the full exception in Python?

303 views Asked by At

I am making a Minecraft Classic server in Python. However, I get the following error in my code:

Unhandled exception in thread started by <bound method Heartbeat.start of <__main__.Heartbeat object at 0x01FC3810>>

Here is my heartbeat code:

import httplib
import time
import thread

def heartbeat(salt = 'wo6kVAHjxoJcInKx', name = 'ElijahCraft', public = 'True', users = '0', maximum = '2', port = '25565'):
    listen = httplib.HTTPConnection('www.minecraft.net')
    listen.request('GET', '/heartbeat.jsp?port=' + port + '&max=' + maximum + '&name=' + name + '&public=' + public + '&version=7&salt=' + salt + '&users=' + users)
    url = listen.getresponse()
    return url.read()

class Heartbeat(object):
    def start(self, salt, name, public, users, maximum, port):
        print 'Server URL:', heartbeat(salt, name, public, users, maximum, port)
        self.users = users
        while not done:
            heartbeat(salt, name, public, self.users, maximum, port)
            time.sleep(45)

    def __init__(self, salt = 'wo6kVAHjxoJcInKx', name = 'ElijahCraft', public = 'True', users = '0', maximum = '2', port = '25565'):
        self.done = False
        thread.start_new_thread(self.start, (salt, name, public, users, maximum, port))

if __name__ == '__main__':
    heart = Heartbeat()

How do I get the full Traceback?

2

There are 2 answers

0
Roger On BEST ANSWER

Wrap your code with try/except

import traceback
import sys

try:
    a = 1 /0


except Exception, inst:
    exc_traceback = sys.exc_info()[2]
    print str(inst) + "\n" + str(traceback.format_tb(exc_traceback)).replace('\\n', '\n')
0
tito On

You can use traceback module, rename your start() method to _start(), and put this one instead:

import traceback

[...]

def start(self, *largs):
    try:
        self._start(*largs)
    except Exception, err:
        exc_type, exc_value, exc_tb = sys.exc_info()
        traceback.print_exception(exc_type, exc_value, exc_tb)