I have a bot made to run super hexagon (just for fun) at http://pastebin.com/X34Qxrxx
Unfortunately, whenever I run it with IDLE 3.5 32 bit, I get the error
Traceback (most recent call last):
File "C:\Users\Spencer\Desktop\Super-Hexagon-Bot\super_hexagon_bot.py", line 223, in <module>
main()
File "C:\Users\Spencer\Desktop\Super-Hexagon-Bot\super_hexagon_bot.py", line 213, in main
window_handle = win32ui.FindWindow(None, u"Super Hexagon").GetSafeHwnd()
NameError: name 'win32ui' is not defined
Can anyone help? I'm not sure how to resolve this issue
Instead of :
window_handle = win32ui.FindWindow(None, u"Super Hexagon").GetSafeHwnd()
try :
window_handle = win32ui.win32ui.FindWindow(None, u"Super Hexagon").GetSafeHwnd()
or
window_handle = FindWindow(None, u"Super Hexagon").GetSafeHwnd()
does this works ?
Related
I've been trying to get a specific (and most likely useless) effect on the traceback when I raise an error.
I would like to hide the raise Exception("Message") of the traceback inside my function and instead have my trace indicate the function call that triggered the raise inside the function
def crash(something):
if something > 200:
raise ValueError("Value too large !")
if __name__ == '__main__':
crash(500)
Normally generates :
Traceback (most recent call last):
File "file.py", line 7, in <module>
crash(500)
File "file.py", line 3, in crash
raise ValueError("Value too large !")
ValueError: Value too large !
Instead I would like to have this :
Traceback (most recent call last):
File "file.py", line 7, in <module>
crash(500)
ValueError: Value too large !
I find it clearer for the user trying to use the module because it clearly shows where the problem is as otherwise he could potentially think the module itself is at fault
I tried to find solution that would "remove" the last call from the traceback but it always had "side effects" like showing part of the code trying to remove the last trace call INSIDE the traceback itself, making it even more confusing. Sometimes it would also repeat the the traceback over what I really want.
For example using this :
def crash():
frame = sys._getframe(1)
tb = types.TracebackType(None, frame, frame.f_lasti, frame.f_lineno)
raise ValueError("Wrong value").with_traceback(tb)
Prints this :
Traceback (most recent call last):
File "file.py", line 34, in <module>
crash()
File "file.py", line 9, in crash
raise ValueError("Wrong value").with_traceback(tb)
File "file.py", line 34, in <module>
crash()
ValueError: Wrong value
I also tried using another function to create the trace myself but ended up with a weird behavior
def crash():
raise exception_no_raise(ValueError("Wrong value"))
def exception_no_raise(exc: Exception):
tb = None
depth = 0
while True:
try:
sys._getframe(depth)
depth += 1
except ValueError:
break
# for i in range(depth-1, 1, -1):
# frame = sys._getframe(i)
# tb = types.TracebackType(tb, frame, frame.f_lasti, frame.f_lineno)
# traceback.print_tb(tb)
# print(file=sys.stderr)
frame = sys._getframe(depth-1)
tb = types.TracebackType(tb, frame, frame.f_lasti, frame.f_lineno)
return exc.with_traceback(tb)
Prints :
Traceback (most recent call last):
File "file.py", line 32, in <module>
crash()
File "file.py", line 7, in crash
raise exception_no_raise(ValueError("Wrong value"))
File "file.py", line 32, in <module>
crash()
ValueError: Wrong value
Even tho when you use traceback.print_tb(tb) (before the return) you get the exact trace I want even tho using it to raise the exception doesn't print it :
File "file.py", line 34, in <module>
crash()
The last solution I found was to "strip" the last traceback from the tb.tb_next chain of traces after catching the exception and then re-raise it (but it showed the raise code anyway so ...)
I have difficulties to grasp how exactly traceback works and it seems that it changes drastically from version to version as I found code from Python 2 and 3 and also code the works in Python 3.8 and not before (related to the fact that you couldn't write to the tb.next of a trace before
Thanks for your help and clarifications !
I'm using Python 3.5.3 and Debian 9
I tried to run this example code from Universe's blog:
import gym
import universe
env = gym.make('flashgames.DuskDrive-v0') #problem here
env.configure(remotes=1)
observation_n = env.reset()
while True:
action_n = [[('KeyEvent', 'ArrowUp', True)] for ob in observation_n]
observation_n, reward_n, done_n, info = env.step(action_n)
env.render()
And I got this error:
WARN: Environment '<class 'universe.wrappers.timer.Timer'>' has deprecated methods '_step' and '_reset' rather than 'step' and 'reset'. Compatibility code invoked. Set _gym_disable_underscore_compat = True to disable this behavior.
Traceback (most recent call last):
File "universe_test.py", line 4, in <module>
env = gym.make('flashgames.DuskDrive-v0')
File "/home/user/.local/lib/python3.5/site-packages/gym/envs/registration.py", line 167, in make
return registry.make(id)
File "/home/user/.local/lib/python3.5/site-packages/gym/envs/registration.py", line 125, in make
patch_deprecated_methods(env)
File "/home/user/.local/lib/python3.5/site-packages/gym/envs/registration.py", line 185, in patch_deprecated_methods
env.seed = env._seed
AttributeError: 'Timer' object has no attribute '_seed'
I also found this question which asks the same thing but isn't answered.
Can you guys help me solve this problem and run the program?
I'm encountering a weird error when running the script in PyCharm's debug mode or inside a Flask app. I have narrowed down my code to the following
import virtualbox
import threading
class ThreadExecutor(threading.Thread):
def __init__(self):
super().__init__()
def run(self):
vbox = virtualbox.VirtualBox()
if __name__ == '__main__':
th = ThreadExecutor()
th.start()
Running this as a module produces no errors and executes perfectly fine but in debug mode it produces the following error message
Connected to pydev debugger (build 181.5087.37)
Exception in thread Thread-6:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 449, in __init__
None)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:/Users/.../dev/debug.py", line 13, in run
vbox = virtualbox.VirtualBox()
File "C:\Program Files\Python36\lib\site-packages\virtualbox\library_ext\vbox.py", line 22, in __init__
manager = virtualbox.Manager()
File "C:\Program Files\Python36\lib\site-packages\virtualbox\__init__.py", line 143, in __init__
self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 991, in __init__
self.platform = PlatformMSCOM(dPlatformParams)
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 455, in __init__
print("Warning: CoInitializeSecurity failed: ", oXctp);
NameError: name 'oXctp' is not defined
Going into \vboxapi__init__.py we find
try:
pythoncom.CoInitializeSecurity(None,
None,
None,
pythoncom.RPC_C_AUTHN_LEVEL_DEFAULT,
pythoncom.RPC_C_IMP_LEVEL_IMPERSONATE,
None,
pythoncom.EOAC_NONE,
None)
except:
_, oXcpt, _ = sys.exc_info();
if isinstance(oXcpt, pythoncom.com_error) and self.xcptGetStatus(oXcpt) == -2147417831: # RPC_E_TOO_LATE
print("Warning: CoInitializeSecurity was already called");
else:
print("Warning: CoInitializeSecurity failed: ", oXctp);
What's causing this error? Does sys.exc_info() behave differently inside a thread inside a debugger?
There seems to be some known, unresolved issues in the interaction between threading and virtualbox, see here. I would suggest using multiprocessing instead as I have not experienced any of the previous issues with it.
I have a bot made to run super hexagon (just for fun) at http://pastebin.com/X34Qxrxx
Unfortunately, whenever I run it with IDLE 3.5 32 bit, I get the error
Traceback (most recent call last):
File "C:\Users\Spencer\Desktop\Super-Hexagon-Bot\super_hexagon_bot.py", line 223, in <module>
main()
File "C:\Users\Spencer\Desktop\Super-Hexagon-Bot\super_hexagon_bot.py", line 213, in main
window_handle = win32ui.FindWindow(None, u"Super Hexagon").GetSafeHwnd()
NameError: name 'win32ui' is not defined
Can anyone help? I'm not sure how to resolve this issue
def main():
try:
print "hardfart"
return 0
except:
return 1
if __name__ == '__main__':
exit(main())
Can one kind programmer tell me why this spits out the following error on exit?
Traceback (most recent call last):
File "C:/Apps/exp_exit.py", line 9, in ,module.
exit(main())
File "C:\Apps\python2.7.2\lib\site.py", line 372 in __call__
raise SystemExit(code)
SystemExit: 0
This is causing an error on exit in a project that's set up similarly. For that project, after using gui2exe to compile an exe, when closing the program I get this related error:
Traceback (most recent call last):
File "checkHDBox.py", line 303, in <module>
NameError: name 'exit' is not defined
So if exit is generating this error, how do I exit then? And if I create an exception handler for exit, doesn't that replace the default action that python takes with the exit function?
Thanks.
Edit:
I think this answers my own question.
The traceback here is from IDLE, I think it's a default behavior from other sources I've read.
Traceback (most recent call last):
File "C:/Apps/exp_exit.py", line 9, in ,module.
exit(main())
File "C:\Apps\python2.7.2\lib\site.py", line 372 in __call__
raise SystemExit(code)
SystemExit: 0
The traceback here was fixed by using sys.exit() instead of exit(0)
Traceback (most recent call last):
File "checkHDBox.py", line 303, in <module>
NameError: name 'exit' is not defined
You exit a program by raising SystemExit. This is what exit() does. Someone has incorrectly written an exception handler that catches all exceptions. This is why you only catch the exceptions you can handle.