Questions tagged [traceback]

A traceback is a report of the actions leading up to a run-time error in the execution of a program.

A traceback is a report of the actions leading up to a run-time error in the execution of a program. For example, the following traceback:

Traceback (most recent call last):
  File "convert.py", line 23, in <module>
    display(literal_eval(sys.argv[1]), *sys.argv[2:])
  File "convert.py", line 16, in display
    result = convert(quantity, from_unit, to_unit)
  File "convert.py", line 10, in convert
    conversion = CONVERSIONS[from_unit, to_unit]
KeyError: ('cm', 'inch')

shows that in the Python program convert.py, the function display() was called, which in turn called the function convert(), which attempted to look up a nonexistent item with the key ('cm', 'inch') in the dictionary CONVERSIONS.

Reporting the actions leading up to an error, rather than just the line on which the error occurred, can assist in debugging a faulty program.

730 questions
18
votes
5 answers

How to create a traceback object

I want to create a traceback like the one returned by sys.exc_info()[2]. I don't want a list of lines, I want an actual traceback object: How can I do this? My goal is to have it include the current stack…
17
votes
1 answer

traceback from a warning

I have a code which, at some point shows a warning, I think that it is having a problem calculating a mean() I would like to know if there is any way to force python to tell me where, or which line, or whatever more information than just this…
codeKiller
  • 5,493
  • 17
  • 60
  • 115
16
votes
3 answers

Can I make Python output exceptions in one line / via logging?

I am using AWS and use AWS cloudwatch to view logs. While things should not break on AWS, they could. I just had such a case. Then I searched for Traceback and just got the lines Traceback (most recent call last): without the actual traceback. I…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
15
votes
3 answers

Catch Python exception and save traceback text as string

I'm trying to write a nice error handler for my code, so that when it fails, the logs, traceback and other relevant info get emailed to me. I can't figure out how to take an exception object and extract the traceback. I find the traceback module…
falsePockets
  • 3,826
  • 4
  • 18
  • 37
15
votes
5 answers

it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time

This traceback mess up all my program and I still cant fix it I have tried all methods and it didn't help! Here's the problem: ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the…
Vethya
  • 153
  • 1
  • 1
  • 6
14
votes
2 answers

How to get value of arguments passed to functions on the stack?

Using: traceback.print_stack() I can get: File "x.py", line 20, in y(x) File "x.py", line 11, in y fun(x) File "x.py", line 8, in fun traceback.print_stack() I there any way to get something like this: File "x.py",…
Adam
  • 2,254
  • 3
  • 24
  • 42
14
votes
2 answers

How can I get a traceback in Perl?

Possible Duplicate: How do I force a stack backtrace for all fatal errors in Perl? One of the things I like about Python, is that when a script exits because of an error, it spits out a traceback. I'm wondering is there anyway of getting a Perl…
Incognito
  • 1,883
  • 5
  • 21
  • 28
14
votes
4 answers

python opencv cv2.waitkey error

i'm trying to test the following code of the getting started page: import numpy as np import cv2 img = cv2.imread('test.jpg', 0) cv2.imshow('image', img) cv2.waitkey(0)&0xFF cv2.destroyAllWindows() But i got this error: init done opengl support…
juanca
  • 361
  • 1
  • 4
  • 13
14
votes
1 answer

Python print last traceback only?

Consider the following code and traceback: >>> try: ... raise KeyboardInterrupt ... except KeyboardInterrupt: ... raise Exception ... Traceback (most recent call last): File "", line 2, in KeyboardInterrupt During handling of…
kiri
  • 2,522
  • 4
  • 26
  • 44
13
votes
5 answers

python file is showing AttributeError: module 'http' has no attribute 'client'

I have the following Python script: import http import requests from bs4 import BeautifulSoup import urllib3 import pyrebase import numpy as np import yagmail import time from datetime import datetime, timedelta import sys import logging import…
e.iluf
  • 1,389
  • 5
  • 27
  • 69
12
votes
1 answer

Getting traceback information from IronPython exceptions

I have IronPython hosted within my application, whenever I catch an exception thrown from a script, I get unhelpful gibberish like this: IronPython.NewTypes.System.Exception_1$1: Error occurred during conversion --->…
jumpinjackie
  • 2,387
  • 4
  • 22
  • 26
12
votes
1 answer

traceback shows up until decorator

This nice little Python decorator can configurably disabled decorated functions: enabled = get_bool_from_config() def run_if_enabled(fn): def wrapped(*args, **kwargs): try: return fn(*args, **kwargs) if enabled else None …
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
12
votes
1 answer

How can I send line number from Python traceback into vim?

I can parse out the paths to the files of a Python traceback, and I can then send those on to Vim using -p on the command line, so that they are opened one file per tab. So I end up with a command like, for example vim -p main.py module.py…
jalanb
  • 1,097
  • 2
  • 11
  • 37
11
votes
3 answers

Is there any way to access nested or re-raised exceptions in python?

A common pattern in python is to catch an error in an upstream module and re-raise that error as something more useful. try: config_file = open('config.ini', 'r') except IOError: raise ConfigError('Give me my config, user!') This will…
Thomas
  • 11,757
  • 4
  • 41
  • 57
11
votes
3 answers

Python logging: disable stack trace

Is there a simple way to disable the logging of an exception stack trace in Python 3, either in a Handler or Formatter? I need the stack trace in another Handler, so setting exc_info=False, in the call to the Logger is not an option. Is there a…
H.T.
  • 141
  • 1
  • 5
1 2
3
48 49