Excel Macro- Not able to run a .exe file - excel

I am using the below code to run an application and even though the app is running it is not showing the desired results. But when I simply double-click the application it runs properly.
RetVal = Shell("D:\Automation Analyzer\Issue Type\dist\PatternDetectorAppv6.0.exe", 1)
The error that is coming on a popup after running this app via the above code is given below.
Traceback (most recent call last):
File "PatternDetectorAppv6.0.py", line 18, in <module>
File "configparser.py", line 959, in __getitem__
KeyError: 'FILE_PATH'
[19428] Failed to execute script PatternDetectorAppv6.0

Related

Python xlwings: EventError: Command failed: Parameter error. (-50)

I wish I could use python to execute the Excel macro, so I tried to use the package xlwings to implement it.
The OS of my laptop is macOS Catalina (ver.: 10.15.7), my compiler is PyCharm (ver.: 2021.2.3), my Python version is 3.8.8, I used Anaconda (Ver.: 22.11.1) as my interpreter, my excel version is 16.66.1 (Microsoft Excel for Mac).
I faced the error "Command Error -1743: The User has declined permission" when I tried to use this package originally, and I solved this issue by installing an old compiler & using the old version of the compiler to run my code. My privacy setting for automation in the app Setting was shown below: (This is NOT the question I want to ask, but I'm not sure if it is also related to the issue I faced, so I still attached it here. I had uninstalled the old version of my compiler already.)
I wish I could implement an existing macro (called Hi) in an existing Excel file (called [StakeOverflow]HelloWorld.xlsm) through Python (represented as MY_PYTHON_FILE.py below), like the snapshot below:
My Excel file and my python code were stored on OneDrive. My macro code was shown below:
Sub Hi()
MsgBox "Good morning!"
End Sub
My python code was shown below:
import xlwings as xw
import time
wb = xw.Book('/Users/<MY NAME>/OneDrive/MY PATH DETAILS/[StakeOverflow]HelloWorld.xlsm')
time.sleep(10)
app = wb.app
macro_vba = app.macro("Hi")
macro_vba()
The code looks really simple, but I still faced the error. My Excel was not opened automatically, and I even could not open the Excel file manually thereafter. The error was shown below:
/Users/.../.conda/envs/Program/bin/python "/Users/.../OneDrive/.../MY_PYTHON_FILE.py"
Traceback (most recent call last):
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/xlwings/main.py", line 4914, in open
impl= self.impl(name)
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/xlwings/_xlmac.py", line 366, in __call__
raise KeyError(name_or_index)
KeyError: '[stakeoverflow] helloworld.xlsm'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/aeosa/appscript/reference.py", line 482, in __call___
return self.AS_appdata.target().event (self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/aeosa/aem/aemsend.py", line 92, in send
raise EventError(errornum, errormsg, eventresult)
aem.aemsend.EventError: Command failed: Parameter error. (-50)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/.../OneDrive/.../MY_PYTHON_FILE.py", line 18, in <module>
wb = xw.Book('/Users/.../OneDrive/.../[stakeoverflow] helloworld.xlsm')
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/xlwings/main.py", line 876, in __init__
impl= app.books.open(
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/xlwings/main.py", line 4921, in open
impl = self.impl.open(
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/xlwings/ xlmac.py", line 420, in open
self.app.xl.open_workbook(
File "/Users/.../.conda/envs/Program/lib/python3.9/site-packages/aeosa/appscript/reference.py", line 518, in __call__
raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
appscript.reference.CommandError: Command failed:
OSERROR: -50
MESSAGE: Parameter error.
COMMAND: app(pid=1647).open_workbook (workbook_file_name='/users/.../onedrive/.../[stakeoverflow] helloworld.xlsm', update_links=k.do_not_update_links, read_only=None, format=None, password=None, write_reserved_password=None, ignore_read_only_recommended=None, origin=None, delimiter=None, editable=None, notify=None, converter=None, add_to_mru=None, timeout=-1)
Process finished with exit code 1
I tried to use terminal to run my python code, but I could not solve the problem, either.
I tried to open the Excel file manually thereafter, the error was shown below:
Excel cannot open the file ’[StakeOverflow]HelloWorld.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.
I tried to Google this error, but few solutions was found. It seems that it is related to the issue of external storage location. I tried to create another Excel file with the same name & macro code on my desktop and try again, and the error would disappear. (However, our company stored the files on OneDrive, so I wish I could utilise the file online.)
Just wondering if anyone here faced this situation before?
I found the answer by myself today. The issue is related to the naming issue rather than the permission issue.
As we could see that the error is KeyError: '[stakeoverflow] helloworld.xlsm', which implies that the problem is here. (Maybe because the system could not find the Excel file with this name.)
I tried to change the name from [stakeoverflow] helloworld.xlsm to helloworld.xlsm, and the error was gone. It seems that when xlwings want to open an Excel file, it would check the validity of the file name and change the name into smaller cases. If the file name contains special characters which are not allowed (e.g., "[]"), then the error would occur.
Notice that I could store the Excel file with these special characters in our laptop & OneDrive, but xlwings did not accept them.
Hope it is helpful to those who face this issue when using xlwings!

Hydrapaper will not open - need help interpreting errors

I'm running Ubuntu 20.04.3 LTS and until recently, I used Hydrapaper for my dual monitor setup. It's not imperative that I be able to have separate wallpapers but I am being driven kind of mad by the errors I'm seeing when I try to open Hydrapaper from the terminal. This is what I get:
michael#michael-Inspiron-7790-AIO:~$ flatpak run org.gabmus.hydrapaper
Traceback (most recent call last):
File "/app/lib/python3.9/site-packages/hydrapaper/__main__.py", line 206, in do_command_line
self.do_activate()
File "/app/lib/python3.9/site-packages/hydrapaper/__main__.py", line 146, in do_activate
self.window = HydraPaperAppWindow()
File "/app/lib/python3.9/site-packages/hydrapaper/app_window.py", line 44, in __init__
self.monitors_flowbox = HydraPaperMonitorsFlowbox()
File "/app/lib/python3.9/site-packages/hydrapaper/monitors_flowbox.py", line 132, in __init__
self.populate()
File "/app/lib/python3.9/site-packages/hydrapaper/monitors_flowbox.py", line 151, in populate
HydraPaperMonitorsFlowboxItem(m), -1
File "/app/lib/python3.9/site-packages/hydrapaper/monitors_flowbox.py", line 71, in __init__
self.set_picture()
File "/app/lib/python3.9/site-packages/hydrapaper/monitors_flowbox.py", line 94, in set_picture
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
gi.repository.GLib.GError: gdk-pixbuf-error-quark: Couldn’t recognize the image file format for file “/home/michael/.var/app/org.gabmus.hydrapaper/cache/org.gabmus.hydrapaper/thumbnails//a5debe6ea02641a70325dc008910a85c61765e55906c29dd338e9f63506378a4.png” (3)
And as I said, Hydrapaper won't open. It appears in my topbar for a few seconds then disappears. Can anyone suggest a fix? Thanks in advance.
I had this same exact issue, what fixed it for me was going to the file mentioned at the end of the error and deleting it, hydra paper worked perfectly after that

Python script runs directly via command line but does not run via shell/bash script

I had a python script main.py it did something and to run it via crontab on a daily basis I created the following file (I think it's called bash script):
#!/bin/sh
source /Users/PathToProject/venv/bin/activate
python /Users/PathToProject/main.py
For some time now it ran daily without any problems.
Now I added a feature that saves a .CSV file containing some results to my google drive via PyDrive2 afterward in the main.py. When running this new script via command line it runs successfully without any errors - every time.
I assumed that the crontab would run as well, but now I get the Traceback below.
/Users/PathToProject/venv/lib/python3.8/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access mycreds.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Traceback (most recent call last):
File "/Users/PathToProject/venv/lib/python3.8/site-packages/oauth2client/clientsecrets.py", line 121, in _loadfile
with open(filename, 'r') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/PathToProject/venv/lib/python3.8/site-packages/pydrive2/auth.py", line 431, in LoadClientConfigFile
client_type, client_info = clientsecrets.loadfile(
File "/Users/PathToProject/venv/lib/python3.8/site-packages/oauth2client/clientsecrets.py", line 165, in loadfile
return _loadfile(filename)
File "/Users/PathToProject/venv/lib/python3.8/site-packages/oauth2client/clientsecrets.py", line 124, in _loadfile
raise InvalidClientSecretsError('Error opening file', exc.filename,
oauth2client.clientsecrets.InvalidClientSecretsError: ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/PathToProject/main.py", line 5, in <module>
main()
File "/Users/PathToProject/version2.py", line 20, in main
PYD.download_file(data_file)
File "/Users/PathToProject/PyDrive_Modul.py", line 58, in download_file
file_ID = get_ID_of_title(filename)
File "/Users/PathToProject/PyDrive_Modul.py", line 47, in get_ID_of_title
drive = google_drive_auth()
File "/Users/PathToProject/PyDrive_Modul.py", line 11, in google_drive_auth
gauth.LocalWebserverAuth()
File "/Users/PathToProject/venv/lib/python3.8/site-packages/pydrive2/auth.py", line 123, in _decorated
self.GetFlow()
File "/Users/PathToProject/venv/lib/python3.8/site-packages/pydrive2/auth.py", line 507, in GetFlow
self.LoadClientConfig()
File "/Users/PathToProject/venv/lib/python3.8/site-packages/pydrive2/auth.py", line 411, in LoadClientConfig
self.LoadClientConfigFile()
File "/Users/PathToProject/venv/lib/python3.8/site-packages/pydrive2/auth.py", line 435, in LoadClientConfigFile
raise InvalidConfigError("Invalid client secrets file %s" % error)
pydrive2.settings.InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
If I edit the python script and skip the part of up/downloading to google drive it works fine.
Now I don't know why this error occurs and how I can solve this problem. The error message seems to be misleading because the client_secrets.json is in the directory and it works via the command line.
When you run via command line it picks path for json file and others.Cron could not find path.Be absolute in path, It will run smoothly. If absolute path not possible, try relative path with respect to CRON location path.

Selenium code running locally but not on server

Both the server and my computer have geckodriver 0.26.0, Firefox 71, and Selenium 3.141.0.
My computer has MacOS Mojave with python 3.8 and the server is CentOS 7 with python 3.7. The code runs perfectly on my computer, but it returns errors on the server.
I don't remember how, but I have been getting different errors depending on if I add breakpoints to it, or if I run it in terminal or submit the job in SLURM.
On terminal:
File "Main.py", line 230, in <module>
main()
File "Main.py", line 179, in main
dfs=get_data(stations, inidate, findate)
File "Main.py", line 113, in get_data
list_files=return_list_day(date)
File "Main.py", line 66, in return_list_day
driver.get(webdir)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette
or
Submitted on SLURM (and most often error):
Traceback (most recent call last):
File "Main.py", line 230, in <module>
main()
File "Main.py", line 179, in main
dfs=get_data(stations, inidate, findate)
File "Main.py", line 113, in get_data
list_files=return_list_day(date)
File "Main.py", line 66, in return_list_day
driver.get(webdir)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/user/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timeout loading page after 300000ms
I can use Selenium without issues in another unrelated code that finishes perfectly fine. So I don't understand why Selenium is having a hard time here or where it comes from.
The code fails here:
## Commented parts are cuz I tried running with the MOZ_HEADLESS tag on terminal
## Didnt make a difference as far as I could tell.
#options = Options()
#options.headless = True
driver = webdriver.Firefox()#options=options)
driver.get(webdir) ##<-- HERE
## Added these because of other replies to this issue I found
driver.implicitly_wait(7)
time.sleep(3)
.
.
.
driver.close()
That bit of codes retrieves a list from the webpage and is ran inside a for-loop. The error is not in the retrieving part, is in driver.get(webdir). I can't share the website since it's literally like looking into the server of a partner institution. webdir is a directory and I am basically waiting till its contents are loaded so I can retrieve its file names.
I know you can't help much without a website, but do the errors I've shown give any indication as to what the problem might be?. Can the retrieving of a specific website behave differently based on OS? I have googled the errors, found questions here, read through them and applied them to see how it changed, and nothing did or I got a different error (either one of the two above).
I found this that states incompatibility between gecko and Mozilla, but since I can successfully run another (unrelated) code with the exact calling and usage of Selenium (only different URL given) then I don't think that's my issue.
Thanks for any help! Let me know what other information I could give that might help.
Edit:
It is not the same as the question that was linked, since I have given it sleep time and didn't change anything. It has 40 GB of ram allocated so its not dying out of too little memory. Which are the solutions shown in this question.
For anyone with this issue, the server updated Firefox to version 79.0 and now it works without any issues. Nothing else was changed as far as I was let known.
I assume the version change fixed it but I don't know exactly how. It's worth a try if anyone else was experiencing the same as I was with different errors depending on how it was run.

Key error while updating all modules in oddo10

using command - python3 odoo-bin --addons=addons,/opt/git_addons/project_abcd -u all &
when i tryied to update modules on server, I am geeting Internal server Error and Error log says:
Traceback (most recent call last):
File "/opt/odoo/odoo/modules/registry.py", line 83, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo/odoo/modules/loading.py", line 373, in load_modules
force, status, report, loaded_modules, update_module, models_to_check)
File "/opt/odoo/odoo/modules/loading.py", line 270, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/opt/odoo/odoo/modules/loading.py", line 153, in load_module_graph
registry.setup_models(cr, partial=True)
File "/opt/odoo/odoo/modules/registry.py", line 300, in setup_models
model._setup_fields(partial)
File "/opt/odoo/odoo/models.py", line 2853, in _setup_fields
field.setup_full(self)
File "/opt/odoo/odoo/fields.py", line 505, in setup_full
self._setup_regular_full(model)
File "/opt/odoo/odoo/fields.py", line 2178, in _setup_regular_full
invf = comodel._fields[self.inverse_name]
KeyError: 'standard_id'
Please help to resolve this error.
Please find the standard_id field in all modules.
Upgrade module which have standard_id field.
If you update -u all with this command line interface then it'll update all your base module first and then you custom modules.
So it might be the reason where your module consist this field and odoo registry can't find it.
With this information it's impossible to say reason for this. One of your modules is trying to refer to a field named stadard_id which doesn't exist.
Try to update your modules one by one and see which one gives this error. Then it's easier to troubleshoot it further.
There may be some dependencies missing from __manifest__.py file.

Resources