FAQ Database Discussion Community


No line number shown for run-time error from Python module

python,numbers,runtime-error,line,traceback
Most Python errors produce traceback showing the line number of the offending statement. But for some reason some run-time errors do not. For instance, running "python -m mymodule.py" on a module containing just the two lines: args = {} if len(args > 2): print("this is a run-time error. Should be:...

How to print the first line from a traceback stack

python,exception,stack-trace,traceback
Suppose I am given the following traceback: Traceback (most recent call last): File "<wingdb_compile>", line 3, in <module> File "C:\Python34\lib\ftplib.py", line 419, in login resp = self.sendcmd('PASS ' + passwd) File "C:\Python34\lib\ftplib.py", line 272, in sendcmd return self.getresp() File "C:\Python34\lib\ftplib.py", line 245, in getresp raise error_perm(resp) ftplib.error_perm: 530 Login incorrect....

EOFError when using raw_input

python,raw-input,traceback,eoferror
I am learning python via codeacademy's python syntax tutorial but when I run the same working code in SublimeText2 the code does not build properly. I have version 2.7 of Python installed on my mac for the record. original = raw_input('Enter a word:') print original I am wondering why this...

Traceback from a Python Script: invalid literal

python,ascii,traceback
In short, what the Python script is supposed to do is to load and calculate ASCII type files. With some previously pre-processed files, it works without errors, while with mine it throws an error. In any case, it looks as though my file is different from what it should be...

traceback behaviour for __init__ errors when using __call__ in metaclasses?

python,metaclass,traceback
Using the following code: class Meta(type): def __new__(mcl, name, bases, nmspc): return super(Meta, mcl).__new__(mcl, name, bases, nmspc) class TestClass(object): __metaclass__ = Meta def __init__(self): pass t = TestClass(2) # deliberate error produces the following: Traceback (most recent call last): File "foo.py", line 12, in <module> t = TestClass(2) TypeError: __init__()...

Importing modules and getting traceback errors in python 2.7

python-2.7,import,traceback
I'm trying to translate a pseudocode into a working Python file. The code, however small, has imported modules in it and I would like to stay as true to the original as I can. When I go to run the script I get an immediate traceback error after I input...

Unexpected traceback on text file in Python

python,file-handling,traceback
I'm experiencing a "Traceback (most recent call last):" error when I try to write to a text file using this code. All three files already exist (although I believe they shouldn't have to - the code should create them if it cannot find them, should it not?), and they are...

How do I can format exception stacktraces in Python logging?

python,logging,traceback
The logs I am creating in Python are intended to be temporarily stored as files which will, in turn, be processed into a log database. They take a pipe-delineated format to dictate how the logs will be processed, but logging.exception() is breaking my standard by adding one too many fields...

how to log tracebacks from uncaught crashes? [duplicate]

python,logging,traceback
This question already has an answer here: Logging uncaught exceptions in Python 7 answers I run a headless and unmanned server which logs everything to a remote server. The application I run there also does this via a SysLogHandler. It works fine. I have cases where the program crashes...

Error when running argument script from textbook

python,typeerror,traceback
I have a beginners coding class for Python. The book we are using is "Coding for Penetration Testers Building Better Tools". During out second chapter we started to create Python scripts and I cannot seem to figure out what is wrong with this script I am supposed to retype from...

Where error happened? exec(compile(script,“”,'exec'))

python,exception,python-3.x,exception-handling,traceback
I have 2 files. In one of them the script (calling the function from another file) is compiled and executed. What I need is to identify where the error occurred: whether it was an error in creating a script (in which line of the script) in the user_script.py or it...