I have an issue by acquiring a VirtualBox Virtual Machine, here's the error code I am getting with the code bellow :
Traceback (most recent call last):
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\library_base.py", line 209, in _call_method
ret = method(*in_params)
File "C:\Users\ROULLE~1\AppData\Local\Temp\gen_py\3.10\D7569351-1750-46F0-936E-BD127D5BC264x0x1x3.py", line 12824, in CreateMachine
ret = self._oleobj_.InvokeTypes(1610743849, LCID, 1, (9, 0), ((8, 1), (8, 1), (8200, 1), (8, 1), (8, 1), (8, 1), (8, 1), (8, 1)),aSettingsFile
pywintypes.com_error: (-2147352561, 'Paramètre non facultatif.', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\ROULLE Diego\Desktop\run_vms.py", line 22, in <module>
pool_web1.acquire("jouca", "troll"),
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\pool.py", line 158, in acquire
clone = machine.clone(name="%s Pool" % self.machine_name)
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\library_ext\machine.py", line 139, in clone
vm_clone = vbox.create_machine(settings_file, name, groups, "", create_flags)
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\library.py", line 10462, in create_machine
machine = self._call(
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\library_base.py", line 200, in _call
return self._call_method(method, in_p=in_p)
File "C:\Users\ROULLE Diego\AppData\Local\Programs\Python\Python310\lib\site-packages\virtualbox\library_base.py", line 222, in _call_method
errobj.msg = exc.args[2][2]
TypeError: 'NoneType' object is not subscriptable
The code :
from virtualbox import VirtualBox, pool
vbox = VirtualBox()
pool_web1 = pool.MachinePool("Web1")
pool_web2 = pool.MachinePool("Web2")
pool_sql1 = pool.MachinePool("SQL1")
sessions = []
while True:
print("1 : create run")
print("2 : release last run")
print("3 : clear all runs")
print("4 : show all ips")
print()
command = input("Command : ")
match command:
case "1":
sessions.append([
pool_web1.acquire("jouca", "troll"),
pool_web2.acquire("jouca", "troll"),
pool_sql1.acquire("jouca", "troll")
])
break
I tried to acquire the VM machine by the MachinePool and it resulted to an error.
Related
Using Prefect to register the workflow with my backend server returns this error:
Traceback (most recent call last):
File "/home/usr/Documents/Test_Automation/Automation/qa-automation/date_validator_Prefect/date_validator.py", line 114, in
flow.register(project_name="QA-Test")
File "/home/usr/.local/lib/python3.9/site-packages/prefect/core/flow.py", line 1726, in register
registered_flow = client.register(
File "/home/usr/.local/lib/python3.9/site-packages/prefect/client/client.py", line 848, in register
serialized_flow = flow.serialize(build=build) # type: Any
File "/home/usr/.local/lib/python3.9/site-packages/prefect/core/flow.py", line 1507, in serialize
self.storage.add_flow(self)
File "/home/usr/.local/lib/python3.9/site-packages/prefect/storage/local.py", line 143, in add_flow
f.write(flow_to_bytes_pickle(flow))
File "/home/usr/.local/lib/python3.9/site-packages/prefect/utilities/storage.py", line 178, in flow_to_bytes_pickle
cloudpickle.dumps(flow, protocol=4), newline=False
File "/home/usr/.local/lib/python3.9/site-packages/cloudpickle/cloudpickle_fast.py", line 73, in dumps
cp.dump(obj)
File "/home/usr/.local/lib/python3.9/site-packages/cloudpickle/cloudpickle_fast.py", line 633, in dump
return Pickler.dump(self, obj)
TypeError: cannot pickle 'weakref' object
It only happens when I try to flow.register(project="QA-test").
If I only add flow.run() it works fine.
This is the beggining of the code:
#task(name="T3")
def feed_validator():
jsonpath = ''
results = []
urlsData = load_data('urls2.json')
for feed in urlsData:
for country in feed["countries"]:
feedUrl = feed['url']
if feed['type'] == 'Availability':
feedUrl = feedUrl.replace('/us/', "/" + country.lower() + "/")
feedData = getFeed(feedUrl)
feedDateInfo = isFeedUpdated(feedData)
if feed['network'] == 'network-samp(gate)':
feed['network'] = 'network-samp'
elif feed['network'] == 'network-samp(samp)':
feed['network'] = 'network-samp2'
country = ''
elif feed['network'] == 'network-samp3(samp3)':
feed['network'] = 'network-samp3'
country = ''
elif feed['type'] == 'Catalog':
country = ''
results.append((feed['platform'], feed['type'], feed['network'], country, feedDateInfo[1]))
orderedResults = multisort(list(results), ((4, False), (1, False), (2, False), (3, False)))
report = email_sender.createResultsEmail(orderedResults)
email_sender.sendEmail(report.as_string())
with Flow("test", storage=Local()) as flow:
feed_validator()
flow.register(project_name="QA-Test")
flow.run()
When using Local storage, Prefect by default uses pickled flow. You can switch to using script storage, as described on this Documentation page
I am trying to write to a macro enabled excel file (xlsm) and then run a macro that is dependent on the cell my script is writing to. For clarity I am on a windows machine, I am not the admin and I am working with python3.8.0
I have a file called write.py, in this file it writes yesterdays date to the A1 cell unless it is Monday then it writes Fridays date. After it writes the date I would like to run a macro that uses that cell/date to do something.
So far I can write yesterdays date and I can run a macro but I cannot do them in the same file. I tried separating the files and executing the macro from the write.py file but that gave me the same error.
Here is my code for the write.py file that writes yesterdays date to the A1 cell of an xlsm file:
from datetime import date
from datetime import timedelta
import openpyxl
path = "C:/Users/project/file.xlsm"
# loads the workbook into a var
book = openpyxl.load_workbook(path)
sheet = book["Sheet2"] # loads a specific sheet by name into a var
a1 = sheet['A1'] # loads a cell into a var
# testing
print(book.sheetnames)
print(a1.value)
# Get yesterdays date unless its a Monday then get Fridays date
today = date.today()
if date.today().weekday() == 0:
yesterday = today - timedelta(days=today.weekday()) + timedelta(days=4, weeks=-1)
else:
yesterday = today - timedelta(days = 1)
yestFormat = (yesterday.strftime("%x")) # formatting the date
# setting the value of the A1 cell to the yesterFormat var
sheet.cell(row=1,column=1,value=yestFormat)
book.save(path)
# This file is supposed to run the macro
exec(open('runMacro.py').read())
Here is the code for the second file that is supposed to run the macro, I have also had this code in the write.py file and I run into the same problems
import xlwings as xw
# loads the workbook into workbook var then loads a specific sheet into worksheet var
wb = xw.Book(r'C:/Users/project/file.xlsm')
wb.macro('test_macro')()
wb.save(r'C:/Users/project/file.xlsm')
When I run the write.py file with the exec command commented out it works and writes the date to the cell. So there is something wrong with the way I am executing the macro. Something I have noticed is if the excel file is open then the write.py file will not work, and the runMacro.py file opens the excel doc when I run it. I think it has something to do with how it is saving or opening but I have read through xlwings documentation and I am doing what it says on how to save, so I am not sure. Hoping there is a better way, thanks for any feedback.
Edit:
Sorry I forgot to add the error I am getting. I have changed the file paths for privacy reasons so there might be some inconsistencies there.
Traceback (most recent call last):
File "C:\Users\project\venv\lib\site-packages\xlwings\_xlwindows.py", line 466, in __call__
return Book(xl=self.xl(name_or_index))
File "C:\Users\project\lib\site-packages\xlwings\_xlwindows.py", line 156, in __call__
v = self._inner(*args, **kwargs)
File "C:\Users\username\AppData\Local\Temp\gen_py\3.8\00020813-0000-0000-C000-000000000046x0x1x8.py", line
39136, in __call__
ret = self._oleobj_.InvokeTypes(0, LCID, 2, (13, 0), ((12, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\project\code\venv\lib\site-packages\xlwings\main.py", line 3873, in open
impl = self.impl(name)
File "C:\Users\project\venv\lib\site-packages\xlwings\_xlwindows.py", line 468, in __call__
raise KeyError(name_or_index)
KeyError: 'sample.xlsm'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/project/test.py", line 35, in <module>
exec(open('test2.py').read())
File "<string>", line 4, in <module>
File "C:\Users\username\venv\lib\site-packages\xlwings\main.py", line 547, in __init__
impl = app.books.open(fullname, update_links, read_only, format, password, write_res_password,
File "C:\Users\username\venv\lib\site-packages\xlwings\main.py", line 3879, in open
impl = self.impl.open(fullname, update_links, read_only, format, password, write_res_password,
File "C:\Users\username\venv\lib\site-packages\xlwings\_xlwindows.py", line 484, in open
return Book(xl=self.xl.Open(fullname, update_links, read_only, format, password, write_res_password,
File "C:\Users\username\venv\lib\site-packages\xlwings\_xlwindows.py", line 66, in __call__
v = self.__method(*args, **kwargs)
File "C:\Users\username\AppData\Local\Temp\gen_py\3.8\00020813-0000-0000-C000-000000000046x0x1x8.py", line
39013, in Open
ret = self._oleobj_.InvokeTypes(1923, LCID, 1, (13, 0), ((8, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Excel cannot open the file 'sample.xlsm' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.", 'xlmain11.chm', 0, -2146827284), None)
My python unit test calls
self.assertRaisesRegex(Exception, "Missing price data for hids: {123}", self.idc_service.load_prices, date(2021, 2, 22), date(2021, 2, 23), [123])
which results in the error:
Failure
Exception: Missing price data for hids: {123}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 59, in testPartExecutor
yield
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 615, in run
testMethod()
File "C:\Users\Alin\Desktop\code\pyApps\pyApps\tests\services\TestIdcDataService.py", line 32, in test_missing_hid_prices
self.assertRaisesRegex(Exception, "Missing price data for hids: {123}", self.idc_service.load_prices, date(2021, 2, 22), date(2021, 2, 23), hids)
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 1285, in assertRaisesRegex
return context.handle('assertRaisesRegex', args, kwargs)
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 178, in handle
callable_obj(*args, **kwargs)
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 217, in __exit__
expected_regex.pattern, str(exc_value)))
File "C:\ProgramData\Miniconda3\lib\unittest\case.py", line 135, in _raiseFailure
raise self.test_case.failureException(msg)
AssertionError: "Missing price data for hids: {123}" does not match "Missing price data for hids: {123}"
The assertion error is confusing because those 2 strings match exactly. Is something going on with the message 'During handling of the above exception, another exception occurred'?
{} has special meaning for regexes, you need to escape them.
self.assertRaisesRegex(Exception, r"Missing price data for hids: \{123\}", self.idc_service.load_prices, date(2021, 2, 22), date(2021, 2, 23), [123])
I want to execute a macro/function code with python script. I have this code example:
from win32com.client import Dispatch
objAccess = Dispatch("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase(strDbName)
objDB = objAccess.CurrentDb()
objAccess.DoCmd.RunMacro('MyMacro')
objAccess.Application.CloseCurrentDatabase()
objAccess.Application.Quit()
del objAccess
del objDB
But I get this error:
Traceback (most recent call last):
File "D:\workspace-python\TOOLS\SHPTOOL\test.py", line 8, in <module>
objAccess.DoCmd.RunMacro('MyMacro')
File "<COMObject <unknown>>", line 3, in RunMacro
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, u"Microsoft Office Access can't find the object 'MyMacro.'", u'ACMAIN11.CHM', 10183, -2146825803), None)
Then I try another approach, call RUN method:
objAccess = Dispatch("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase(strDbName)
objDB = objAccess.CurrentDb()
objAccess.Run('merge', "mystringparameter")
objAccess.Application.Quit()
error:
Traceback (most recent call last):
File "D:\workspace-python\TOOLS\SHPTOOL\test.py", line 58, in <module> objAccess.Run('merge', "mystringparameter")
File "<COMObject Access.Application>", line 14, in Run
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, u"Microsoft Office Access can't find the procedure 'merge.'", None, -1, -2146825771), None)
And my MDB code, the 3 functions:
Sub merge(path As String)
MsgBox "Inside generated macro!!! " & path
End Sub
Sub MyMacro()
MsgBox "Inside generated macro!!!"
End Sub
Function MyFunction()
MsgBox "You MUST select a Destination Folder!"
End Function
Thanks
Just replace
objAccess.DoCmd.RunMacro('MyMacro')
by
objAccess.run('MyMacro')
\o/
I am trying to use evdev to simulate touch input.
from evdev import UInput, AbsInfo, ecodes as e
cap = {
e.EV_KEY : [e.KEY_A, e.KEY_B],
e.EV_ABS : [
(e.ABS_X, AbsInfo(value=0, min=0, max=255,
fuzz=0, flat=0, resolution=0)),
(e.ABS_Y, AbsInfo(0, 0, 255, 0, 0, 0)),
(e.ABS_MT_POSITION_X, (0, 255, 128, 0)) ]
}
ui = UInput(cap, name='example-device', version=0x3)
Adding myself to the input group, the error is:
Traceback (most recent call last):
File "mouse.py", line 12, in <module>
ui = UInput(cap, name='example-device', version=0x3)
File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 125, in __init__
self._verify()
File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 221, in _verify
raise UInputError(msg.format(self.devnode))
evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing
After running chmod +0666 /dev/uinput the error changes to:
Traceback (most recent call last):
File "mouse.py", line 12, in <module>
ui = UInput(cap, name='example-device', version=0x3)
File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 147, in __init__
_uinput.create(self.fd, name, vendor, product, version, bustype, absinfo)
SystemError: /builddir/build/BUILD/Python-3.6.2/Objects/longobject.c:404: bad argument to internal function
Removing (e.ABS_MT_POSITION_X, (0, 255, 128, 0)):
Traceback (most recent call last):
File "mouse.py", line 12, in <module>
print(ui)
File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 171, in __str__
evtypes = [i[0] for i in self.capabilities(True).keys()]
File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 200, in capabilities
raise UInputError('input device not opened - cannot read capabilites')
evdev.uinput.UInputError: input device not opened - cannot read capabilites