Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError on Windows #41

Closed
ilkergzlkkr opened this issue Oct 21, 2022 · 9 comments · Fixed by #47 or #55
Closed

OSError on Windows #41

ilkergzlkkr opened this issue Oct 21, 2022 · 9 comments · Fixed by #47 or #55

Comments

@ilkergzlkkr
Copy link
Contributor

ilkergzlkkr commented Oct 21, 2022

  • Desktop Notifier version: 3.4.1
  • Python version: Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
  • Operating System: Windows 10 Pro 21H2 19044.2130
  • Virtualenv: packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
$ pip freeze
desktop-notifier==3.4.1
packaging==21.3
pyparsing==3.0.9
winsdk==1.0.0b7

What I Did

I tried to run basic example on README

Result

Traceback (most recent call last):
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\main.py", line 4, in <module>
    notifier = DesktopNotifier()
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\venv\lib\site-packages\desktop_notifier\main.py", line 161, in __init__
    self._impl = impl_cls(app_name, app_icon, notification_limit)
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\venv\lib\site-packages\desktop_notifier\winrt.py", line 74, in __init__
    self.notifier = self.manager.create_toast_notifier(self._appid)
OSError: [WinError -2147024809] Parametre hatalı

Parametre hatalı -> The parameter is incorrect (in english)

@samschott
Copy link
Owner

Thanks for the report. I no longer have access to a Windows VM, after switching to an Apple Silicon mac, so this will be difficult for me to reproduce or fix. If you are able to contribute a fix, this would be very much appreciated!

As a pointer, the windows backend gets the app ID directly from CoreApplication:

self._appid = CoreApplication.get_id()
self.manager = ToastNotificationManager.get_default()
self.notifier = self.manager.create_toast_notifier(self._appid)

The documentation for ToastNotificationManager is available at https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toastnotificationmanager/

@iamkroot
Copy link
Contributor

Looks like a general Windows bug. One of my users also got this- iamkroot/trakt-scrobbler#224

Will try to debug in Windows if I get some time.

@samschott
Copy link
Owner

Looks like the winrt API changed slightly during the last couple of release (it is still in beta, so I don't blame them).

I've made adjustments accordingly and released v3.4.2.dev0 of desktop-notifier. Could you see if this fixes this issue?

@ilkergzlkkr
Copy link
Contributor Author

Sorry for being late to reply.
Using v3.4.2.dev0, i still get the OSError: [WinError -2147024809]

Is there any way to use Github Actions Workflow to check windows is being able to run the example code in repo.

@ilkergzlkkr
Copy link
Contributor Author

ilkergzlkkr commented Nov 16, 2022

CoreApplication.get_id() does not work, AppId is always nonestr (self._appid='')
While i was searching, found this: pywinrt/pywinrt#28

  • i tried to hardcode self._appid as 'hi'
  • resulted as error in BackgroundTaskRegistration.get_all_tasks()
Notification failed
Traceback (most recent call last):
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\venv\lib\site-packages\desktop_notifier\base.py", line 207, in send
    platform_nid = await self._send(notification, notification_to_replace)
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\venv\lib\site-packages\desktop_notifier\winrt.py", line 128, in _send
    await self._request_background_task_access()
  File "C:\Users\ilker\Desktop\dev\env-trash\desktop-notifier\venv\lib\site-packages\desktop_notifier\winrt.py", line 97, in _request_background_task_access
    tasks = BackgroundTaskRegistration.get_all_tasks()
OSError: [WinError -2147023728] Eleman bulunamadı ((Child not found in english))

Now it works! 😊👌
image

Note: I also used the basic notification toast with hacky id and any string values

# using hacky _appid
await notifier.send(
        title="Julius Caesar",
        message="Et tu, Brute?",
    )

I had to use the hacky id to run the toast. This is the only way i can get it work.

@samschott
Copy link
Owner

samschott commented Nov 16, 2022

Ah, I see, you are practically impersonating another app to show notifications.

I expect that Windows has similar policies as macOS around only allowing proper "applications" to send desktop notifications, but with a lot weaker enforcement of those policies.

How did you install Python? When using the official installer from python.org, it should behave properly with an App ID of "Python". Likewise, if you use desktop-notifier from a proper app, created for example with pyinstaller or briefcase, it should also just work.

This error should definitely be handled more gracefully with a better error message so that users understand what is going on.

@ilkergzlkkr
Copy link
Contributor Author

I used python.org for windows indeed. I am using Virtualenv, may be that is the case idk.

@iamkroot
Copy link
Contributor

iamkroot commented Jan 6, 2023

@samschott
I'm not sure if the issue is fixed yet. Simply trying to run an app causes a crash-

OSError

[WinError -2147024809] The parameter is incorrect

at .local\pipx\venvs\trakt-scrobbler\Lib\site-packages\desktop_notifier\winrt.py:74 in init
70│ ) -> None:
71│ super().init(app_name, app_icon, notification_limit)
72│ self._appid = CoreApplication.get_id()
73│ self.manager = ToastNotificationManager.get_default()
→ 74│ self.notifier = self.manager.create_toast_notifier(self._appid)
75│
76│ # BackgroundExecutionManager.remove_access(self._appid)
77│ # CoreApplication.add_background_activated(self._on_background_activated)
78│

(from iamkroot/trakt-scrobbler#224 (comment))

To repro, pipx install trakt-scrobbler followed by trakts init on Windows.

@samschott
Copy link
Owner

Darn, looks like this was a stupid oversight of me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants