I have a function that decodes an exception and pushes the info to a file. Following is what I do basically:
exc_info = sys.exc_info
txt = cgitb.text(exc_info)
Using this, I got the following exception trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\job_queue\utils\start_workers.py", line 40, in start_worker
worker_loop(r_jq, worktype, worker_id)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 55, in worker_loop
_job_machine(*job)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 34, in _job_machine
do_verbose_exception()
File "C:\Python27\lib\site-packages\job_queue\server\errors.py", line 23, in do_verbose_exception
txt = cgitb.text(exc_info)
File "C:\Python27\lib\cgitb.py", line 214, in text
formatvalue=lambda value: '=' + pydoc.text.repr(value))
File "C:\Python27\lib\inspect.py", line 885, in formatargvalues
specs.append(strseq(args[i], convert, join))
File "C:\Python27\lib\inspect.py", line 840, in strseq
return convert(object)
File "C:\Python27\lib\inspect.py", line 882, in convert
return formatarg(name) + formatvalue(locals[name])
KeyError: 'connection'
I ran the code multiple times after this exception, but couldn't reproduce it. However, I didn't find any reference in files cgitb.py or inspect.py to a dict with 'connection' key either.
Will anybody know if this is an issue with python's cgitb or inspect files? Any helpful inputs?
You passed a wrong type to text function
below is the correct way.
cgitb.text((sys.last_type, sys.last_value, sys.last_traceback))
Im not sure specifically why this exception is happening, but have you read the docs for cgitb module? It seems that since python 2.2 it has supported writing exceptions to a file:
http://docs.python.org/library/cgitb.html
Probably something like:
cgitb.enable(0, "/my/log/directory") # or 1 if you want to see it in browser
As far as your actual traceback, are you sure 'connection' isnt a name you are using in your own code? 'inspect' module is most likely trying to examine your own code to build the cgi traceback info and getting a bad key somewhere?
Related
I am having a super weird error, the situation is the following:
I am writing some code in a package called hsltools. The Module is called em_combiner1_4. I recently changed the version from 1_3, and also changed all imports accordingly.
If I run my code now, I get the following error:
Traceback (most recent call last):
File "C:\Users\...\git_home\hsltools\hsltools\tests\emc_tester\EMC_tester.py", line 85, in <module>
combine_2d()
File "C:\Users\...\git_home\hsltools\hsltools\tests\emc_tester\EMC_tester.py", line 48, in combine_2d
elec_field2d = emc.EM(import_path+"2DelecMap.ef2.npz")
File "c:\users\...\git_home\hsltools\hsltools\em_combiner1_4.py", line 441, in __init__
load_npz()
File "c:\users\...\git_home\hsltools\hsltools\em_combiner1_4.py", line 251, in load_npz
self.em_type = data["metadata"][1]
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 254, in __getitem__
return format.read_array(bytes,
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\lib\format.py", line 744, in read_array
array = pickle.load(fp, **pickle_kwargs)
ModuleNotFoundError: No module named 'hsltools.em_combiner1_3
The thing I don't get is the location of the error: ...\numpy\lib\format.py.
There is absolutaly no import there, and anyway, numpy would not import my module.
I am wondering if I am generally misunderstanding some basic concept, or if the error is wrong.
It's happening while deserializing pickled objects. Pickle stores the type information including the module name. When loading a pickled object, the module is imported to construct the final object.
Your pickle file contains an object that is part of hsltools.em_combiner1_3. So that is the module pickle tries to find.
I wanted to learn about python's Blessed library, maybe make a text-based game or some useful thing. but no matter what code write, whenever I import blessed I get an error report.
Ive tried various code, including examples of complete code which have worked for other people, but its always the same error.
This is some simple code since it doesn't seem to matter...
from blessed import Terminal
t = Terminal()
print('Code that does nothing.')
this is the error..
Traceback (most recent call last):
File "/usr/lib/python3.7/sre_parse.py", line 1015, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\d'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/drew/TBG/test.py", line 3, in <module>
t = blessed.Terminal()
File "/usr/lib/python3/dist-packages/blessed/terminal.py", line 226, in __init__
self.__init__capabilities()
File "/usr/lib/python3/dist-packages/blessed/terminal.py", line 244, in __init__capabilities
name, cap, attribute, **kwds)
File "/usr/lib/python3/dist-packages/blessed/sequences.py", line 134, in build
pattern = re.sub(r'\d+', _numeric_regex, _outp)
File "/usr/lib/python3.7/re.py", line 194, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/lib/python3.7/re.py", line 311, in _subx
template = _compile_repl(template, pattern)
File "/usr/lib/python3.7/re.py", line 302, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "/usr/lib/python3.7/sre_parse.py", line 1018, in parse_template
raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 0
I've tried googling obviously but found no one having this issue with blessed, just other escape code errors which I dont have the knowledge to apply to this instance. I tried following the exception through those files but their contents are beyond my level (and I don't have permission to change them anyway, which is for the best).
I'm running ubuntu 14.04, have python 3.7.8 as default and blessed 1.17.8 installed.
Please help me determine whats causing this error.
Trying to setup client Python script in my Windows system and finally i got stuck up with the below error, Tried in the Google and myself of about 4 hrs. But not able find out the solution. Since i am very new to the Python, I could not able to find out the solution.
Please have a look at below code and its error, So you may have solution for me,
Error:
C:\Python26>python C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py
Traceback (most recent call last):
File "C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py", line 12, in <module>
import injectdir
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\__init__.py", line 10, in <module>
import action
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\__init__.py", line 1, in <module>
from command import list
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\command.py", line 28, in <module>
action_list[action.name]=action
AttributeError: 'module' object has no attribute 'name'
Code: (Line no: 19 to 28)
try:
action_list={}
for file in filenames:
if file.endswith('.py') and file != '__init__.py' and file != 'command.py':
#Import the file as a module action_imp
exec "import {0} as action_imp".format(file[0:-3])
#Get the action object from action_imp. Name is a required method for all actions
action=action_imp
#Put the file name in file_name
action.file_name=file[0:-3]
action_list[action.name]=action
except:
This seems like a array attribute error. So i have tried with if condition, But no luck so far.
So i have stuck with the last line ( "action_list[action.name]=action" ). Please let me know if you have any suggestions or any quick solution to suppress the error in the for loop.
Thanks.
As the comment after the exec statement says, every action has to have a name.
Ensure that every file listed in filenames (except __init__.py and command.py) contains a variable name.
Alternatively, you can suppress the error by replacing line 28 with:
try:
action_list[action.name]=action
except AttributeError:
print "Could not register action", action.file_name
I'm testing ebaysdk Python library that lets you connect to ebay. Now I'm trying examples from: https://github.com/timotheus/ebaysdk-python/
So far I got stuck at this example:
from ebaysdk.shopping import Connection as Shopping
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file="ebay.yaml")
response = shopping.execute('FindPopularItems',
{'QueryKeywords': 'Python'})
print response.disct()
When I run it. It gives me this error:
Traceback (most recent call last):
File "ebay-test.py", line 13, in <module>
{'QueryKeywords': 'Python'})
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 123, in execute
self.error_check()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 193, in error_check
estr = self.error()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 305, in error
error_array.extend(self._get_resp_body_errors())
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/shopping/__init__.py", line 188, in _get_resp_body_errors
dom = self.response.dom()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 229, in dom
return self._dom
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 216, in __getattr__
return getattr(self._obj, name)
AttributeError: 'Response' object has no attribute '_dom'
Am I missing something here or it could be some kind of bug in library?
Do you have a config file? I had a lot of problems getting started with this SDK. To get the yaml config file to work, I had to specify the directory that it was in. So in your example, it would be:
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ebay.yaml'))
You should also be able to specify debug=true in your Shopping() declaration as in Shopping(debug=True).
Make sure if you have not, to specify your APP_ID and other necessary values in the config file.
You have the wrong domain, it should be open.api.sandbox.ebay.com. See this page on the ebaysdk github.
Hello I am running Python 2.5 on Windows and whenever my application gets an exception rather than seeing the debug information I get an error inside of the traceback.py file itself. Anyone know a fix for this mb a patch or replacement file.
Traceback (most recent call last):
File "C:\Python25\lib\logging\__init__.py", line 744, in emit
msg = self.format(record)
File "C:\Python25\lib\logging\__init__.py", line 630, in format
return fmt.format(record)
File "C:\Python25\lib\logging\__init__.py", line 426, in format
record.exc_text = self.formatException(record.exc_info)
File "C:\Python25\lib\logging\__init__.py", line 398, in formatException
traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
File "C:\Python25\lib\traceback.py", line 126, in print_exception
lines = format_exception_only(etype, value)
File "C:\Python25\lib\traceback.py", line 176, in format_exception_only
stype = etype.__name__
AttributeError: 'NoneType' object has no attribute '__name__'
===EDIT===
Found same error in mailing list here outdated answer it seems
http://mail.python.org/pipermail/python-dev/2006-September/068975.html
Possible causes:
Calling logging.exception() when there is no active exception
Calling a logging function with exc_info=1, when there is no active exception.
Calling a logging function with exc_info=(None, None, None) to a logging function (e.g. if doing the exception logging manually).
You should not use logging.exception outside of an except block.
The exception is caused by a None exception type passed to traceback.print_exception, meaning that there is no active exception to process.
Meanwhile, the newsgroup posting you linked to indicates that it was a regression in the standard library that resulted in that particular traceback. You may want to try upgrading your Python to 2.5.1, which fixed this particular problem.