How to fix Python Pywinauto KeySequence Error - python

I'm trying to enter (Alt + Windows Key) in a script to my application. I have defined type_keys
def type_keys(string, element):
"""Type a string char by char to Element window"""
for char in string:
element.type_keys(char)
Then calling it during a save here:
# Save
print("Saving")
type_keys("%{VK_LWIN down}", win)
#wait_win_ready(win)
time.sleep(10)
type_keys("1", win)
win.wait("enabled", timeout = REFRESH_TIMEOUT)
I'm getting an error that seems my syntax is incorrect - but not sure how to fix.
Saving
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\pbixrefresher.exe\__main__.py", line 9, in <module>
File "c:\python36\lib\site-packages\pbixrefresher\pbixrefresher.py", line 67, in main
type_keys("%{VK_LWIN down}", win)
File "c:\python36\lib\site-packages\pbixrefresher\pbixrefresher.py", line 13, in type_keys
element.type_keys(char)
File "c:\python36\lib\site-packages\pywinauto\base_wrapper.py", line 971, in type_keys
vk_packet)
File "c:\python36\lib\site-packages\pywinauto\keyboard.py", line 710, in send_keys
vk_packet=vk_packet)
File "c:\python36\lib\site-packages\pywinauto\keyboard.py", line 621, in parse_keys
raise KeySequenceError('`}` not found')
pywinauto.keyboard.KeySequenceError: `}` not found
Hoping for some help on why I'm receiving this error! Thanks for reading.

This is a typo in this line: type_keys("%{VK_LWIN down}", win) which should be element.type_keys("%{VK_LWIN down}")
The problem is that your implementation of type_keys unrolls the sequence to the something like this:
element.type_keys("%")
element.type_keys("{") # fails here, absolutely expected!
element.type_keys("V")
element.type_keys("K")
element.type_keys("_")
element.type_keys("L")
element.type_keys("W")
element.type_keys("I")
element.type_keys("N")
element.type_keys(" ") # it won't be typed without param `with_spaces=True` (default is False)
element.type_keys("d")
element.type_keys("o")
element.type_keys("w")
element.type_keys("n")
element.type_keys("}")

Related

junit2html : could not find test suites in result xml

I am running a jenkins pipeline for my testing project using ctest, and I want to have a test report for it.
When I try to use junit2html to parse the output of Test.xml, which is generated by ctest, it will throw could not find test suites in results xml error.
Does anyone knows that how this error occurs and how to fix it?
Thanks in advance.
Details
After I generate the test report with ctest:
ctest --no-compress-output -T Test
# generate Testing/<date-time>/Test.xml
Then I want to create a html report by junit2html module :
python3 -m junit2htmlreport Testing/*/Test.xml
It will throw an error :
$ python3 -m junit2htmlreport Testing/20220802-0720/Test.xml test_report.html
Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/__main__.py", line 6, in <module>
runner.start()
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/runner.py", line 103, in start
run(sys.argv[1:])
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/runner.py", line 90, in run
report = parser.Junit(args[0])
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/parser.py", line 340, in __init__
self.process()
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/parser.py", line 376, in process
raise ParserError("could not find test suites in results xml")
junit2htmlreport.parser.ParserError: could not find test suites in results xml

Python3.9.0 Idle Wont Open How Do I Fix This?

I am not sure why my python 3.9 idle isnt opening VIDEO I have tried multiple times but it still isnt opening for me
I tried repairing it in control panel but it still isnt working
I also tried to reinstall it but I am still having the same problem it just wont open no matter how much I click
my idle path on my folder enter image description here
C:\Users\Habib\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9
on my IDle properties it says V
TARGET: C:\Users\Habib\AppData\Local\Programs\Python\Python39\pythonw.exe "C:\Users\Habib\AppData\Local\Programs\Python\Python39\Lib\idlelib\idle.pyw"
START: C:\Users\Habib\AppData\Local\Programs\Python\Python39\
OUTPUT I GET WHEN I PUT py -m idlelib
Traceback (most recent call last):
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\__main__.py", line 6, in <module>
import idlelib.pyshell
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\pyshell.py", line 49, in <module>
from idlelib.colorizer import ColorDelegator
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\colorizer.py", line 6, in <module>
from idlelib.config import idleConf
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\config.py", line 766, in <module>
idleConf = IdleConf()
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\config.py", line 166, in __init__
self.LoadCfgFiles()
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\config.py", line 758, in LoadCfgFiles
self.userCfg[key].Load() #same keys
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\idlelib\config.py", line 77, in Load
self.read(self.file)
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\configparser.py", line 697, in read
self._read(fp, filename)
File "C:\Users\Habib\AppData\Local\Programs\Python\Python39\lib\configparser.py", line 1082, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: 'C:\\Users\\Habib\\.idlerc\\config-main.cfg', line: 1
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Python 3.9 is very new and it may not be working with your system try switching back to python 3.8.6 and it looks like you havent added python to path
I had the same problem and I was trying to open (pythonw.exe)
it turns out that I had to open Python\Lib\idlelib\idle.py type(python file(no console))

View error traceback when running commands from VS Code Python debugger

When I use the VS Code debugger with Python to stop at some breakpoints, I often write some lines straight in the debug console (use it as interactive Python shell within my program).
The problem is, when I have errors in these lines, when typed from the debug console, I don't see the full Python-style traceback of the error, but only the last line (<Error_type>: ), i.e., without references to code file where the error was raised, the line raised it, and the full stack trace.
Is there any way to configure the VS Code debugger to show the full traceback for errors raised by lines executed from the debugger?
I develop (and debug) on remote machine through ssh.
Example:
I wrote a file named tmp2.py, which contains:
class A:
def __init__(self, val):
print(val)
a = A()
If I put debug point on line 5: print('start'),
and then from the debug console type directly a = A(), I see this one line output:
TypeError: __init__() missing 1 required positional argument: 'val'
but if I run the full program I see the this elaborated output:
Traceback (most recent call last):
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/innereye/deeplearning/tmp2.py", line 6, in <module>
a = A()
TypeError: __init__() missing 1 required positional argument: 'val'
which directs me to the actual file and line where the error raises.
I want the debugger to show me the second output also for lines executed directly from the debug console.
Sorry, but it seems like impossibleļ¼Œ VSCode hasn't provided related configuration. And I consider that's very hard to get what you want, this is because of the debug theory.

Python Behave BDD Tutorial Error on Windows

So, I`m comparing some python test frameworks and came across behave. Thought it was interesting and worth a test drive.
Followed the steps on the tutorial, available at:
https://behave.readthedocs.io/en/stable/tutorial.html
When I ran the behave command on Powershell (Win10 and Python 2.7.10), I got the following error:
Exception TypeError: compile() expected string without null bytes
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\behave\__main__.py", line 187, in <module>
sys.exit(main())
File "C:\Python27\lib\site-packages\behave\__main__.py", line 183, in main
return run_behave(config)
File "C:\Python27\lib\site-packages\behave\__main__.py", line 127, in run_behave
failed = runner.run()
File "C:\Python27\lib\site-packages\behave\runner.py", line 804, in run
return self.run_with_paths()
File "C:\Python27\lib\site-packages\behave\runner.py", line 809, in run_with_paths
self.load_step_definitions()
File "C:\Python27\lib\site-packages\behave\runner.py", line 796, in load_step_definitions
load_step_modules(step_paths)
File "C:\Python27\lib\site-packages\behave\runner_util.py", line 412, in load_step_modules
exec_file(os.path.join(path, name), step_module_globals)
File "C:\Python27\lib\site-packages\behave\runner_util.py", line 385, in exec_file
code = compile(f.read(), filename2, "exec", dont_inherit=True)
TypeError: compile() expected string without null bytes
Has anyone encountered this error while trying to run behave? (Found some threads online related mainly to flask issues but I couldn't solve the problem)
Answering my own question here.
It was an encoding problem.
Sublime was saving my files with an encoding different from UTF-8.
File -> Save with Encoding -> UTF-8 did the trick.

Open a new instance of AutoCAD via Python

Does anyone have any experience using Python with AutoCAD? I'm just trying, as a test to see if I can open a new instance of AutoCAD via Python and though that PyAutocad worked well (feel free to offer other suggestions, if you have any).
Anyway based on the doc (https://pypi.python.org/pypi/pyautocad/#downloads) - it says these lines of code should do it, but nothing's happened as of yet.
from pyautocad import Autocad, APoint
acad = Autocad()
acad.prompt("Hello, Autocad from Python\n")
Just these lines of code should generate info on the commandline but instead results in about 50 lines worth of traceback (which I can post as well if anyone's interested) - any ideas?
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
acad.prompt("Hello, Autocad")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 54, in app
self._app = comtypes.client.GetActiveObject('AutoCAD.Application')
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 180, in GetActiveObject
obj = comtypes.GetActiveObject(clsid, interface=interface)
File "C:\Python27\lib\site-packages\comtypes\__init__.py", line 1165, in GetActiveObject
oledll.oleaut32.GetActiveObject(byref(clsid), None, byref(p))
File "_ctypes/callproc.c", line 941, in GetResult
WindowsError: [Error -2147221021] Operation unavailable
After adding the VBA Module, the traceback now reads:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
acad.prompt("Hello")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 54, in app
self._app = comtypes.client.GetActiveObject('AutoCAD.Application')
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 183, in GetActiveObject
return _manage(obj, clsid, interface=interface)
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:\Python27\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: 'module' object has no attribute 'IAcadApplication'
Now after deleting comtypes' "gen" folder per #reclosedev, Autocad now opens but the string of text still will not appear on the command line - the traceback reads:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
acad.prompt("Hello")
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 153, in prompt
self.doc.Utility.Prompt(u"%s\n" % text)
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 65, in doc
return self.app.ActiveDocument
File "C:\Python27\lib\site-packages\pyautocad\api.py", line 59, in app
self._app.Visible = self._visible
File "C:\Python27\lib\site-packages\comtypes\client\dynamic.py", line 116, in __setattr__
dispid = self._comobj.GetIDsOfNames(name)[0]
File "C:\Python27\lib\site-packages\comtypes\automation.py", line 643, in GetIDsOfNames
self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids)
COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
Have you considered IronPython?
http://through-the-interface.typepad.com/through_the_interface/2009/03/using-ironpython-with-autocad.html
Here's a quick example of how it could be leveraged:
import clr
import System
from System import Type, Activator
acApp = Activator.CreateInstance(Type.GetTypeFromProgID("AutoCAD.Application"))
acApp.Visible = 1
acApp.ActiveDocument.SendCommand("(Princ \"Hello World from Python!\")(Princ)\n")
Obviously the ProgId will correspond to whichever version of AutoCAD was opened last.

Categories

Resources