pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

Error: pywintypes.com_error: (-2147024891, 'Access is denied.', None, None)

Open umamahesh0123 opened this issue 3 years ago • 2 comments

Note that issues in this repository are only for bugs or feature requests in the pywin32.

If you need support or help using this package, please follow these instructions - support or help requests will be closed without comment.

For all bugs, please provide the following information.

  • Expected behavior and actual behavior. Expected to run the VB Macros from xlsm file Error: File "D:\Program Files\Python37\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch IDispatch = pythoncom.connect(IDispatch) pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "W:\WAY4DTNA\Jenkins_2_391_1_Repository\SAP20163\workspace\Uma_Test_RF_WAY4Runner_TestCase\exec_3\svn\automation\automation\V2\RobotFramework/Testcases\runtdsgen.py", line 51, in runmacro() File "W:\WAY4DTNA\Jenkins_2_391_1_Repository\SAP20163\workspace\Uma_Test_RF_WAY4Runner_TestCase\exec_3\svn\automation\automation\V2\RobotFramework/Testcases\runtdsgen.py", line 44, in runmacro xl=win32com.client.Dispatch("Excel.Application") File "D:\Program Files\Python37\lib\site-packages\win32com\client_init_.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\Program Files\Python37\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Program Files\Python37\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147024891, 'Access is denied.', None, None)

  • Steps to reproduce the problem. Run the program from Jenkins, If it from manual local machine it is working fine

def runmacro(): workbook = load_workbook(PATH_IN_XLS + "/" + TRANSACTIONS_SPECS, keep_vba=True) #Sheet name from the specification to be accessed sheet = workbook["Trx_Specs_Sheet"] #Details are filling into excel sheet['E2'] = TRANS_DATE sheet['E3'] = SEQ_NUM sheet['E5'] = RUN_NUM sheet['G3'] = PATH_RESULT #This part fills in excel to inform the TDS UFX files are geenrating from Automation not Manual sheet['G2'] = 'A' #The SENDER will be passed into excel sheet['G5'] = SENDER workbook.save(PATH_IN_XLS + "/" + TRANSACTIONS_SPECS)

#Below functionality helps to trigger the VB Macro which is in .xlsm file
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(os.path.abspath(PATH_IN_XLS + "/" + TRANSACTIONS_SPECS))
xl.Application.Run(TRANSACTIONS_SPECS + mymacro)
xl.Application.Quit() 
del xl

runmacro()

  • Version of Python and pywin32 Don't have full idea

umamahesh0123 avatar Oct 11 '22 13:10 umamahesh0123

This is going to be something related to the Jenkins environment - possibly that Excel is installed under a different user than the script is being run uder.

mhammond avatar Oct 12 '22 01:10 mhammond

Thank you for response, yeah you are correct , it is running find under my user id in local machine, When I run from the jenkins it is using different user and the same user has full permission as like my user id.

umamahesh0123 avatar Oct 12 '22 06:10 umamahesh0123

Not much we can do here.

mhammond avatar Oct 21 '22 08:10 mhammond

Hi @umamahesh0123, I am facing same error while trying to access Omicron. I have configured windows self-hosted runner and running automation testing code for web application developed via Selenium. If you have fix around it could please share the details for the same. That would be great help. Thanks.

Ashish-eaton avatar May 24 '24 11:05 Ashish-eaton