phuhl / notify-send.py

A python-script like libnotify but with improved functionality
Other
96 stars 13 forks source link

--replaces-process causes an error in Python 3.7 #17

Closed bedax closed 3 years ago

bedax commented 3 years ago

When using the latest version of notify-send.py, I get the following:

> notify-send.py --replaces-process some-process message
Traceback (most recent call last):
  File "/home/tom/.local/lib/python3.7/site-packages/notify_send_py/notify_send_py.py", line 126, in notify
    conn = Client(pidf.read())
  File "/usr/lib/python3.7/multiprocessing/connection.py", line 487, in Client
    family = family or address_type(address)
  File "/usr/lib/python3.7/multiprocessing/connection.py", line 108, in address_type
    raise ValueError('address type of %r unrecognized' % address)
ValueError: address type of b'' unrecognized

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.local/bin/notify-send.py", line 10, in <module>
    sys.exit(main())
  File "/home/tom/.local/lib/python3.7/site-packages/notify_send_py/notify_send_py.py", line 218, in main
    NotifySendPyCLI()
  File "/home/tom/.local/lib/python3.7/site-packages/notify_send_py/notify_send_py.py", line 211, in __init__
    dontQuitOnAction=args.dontQuitOnAction
  File "/home/tom/.local/lib/python3.7/site-packages/notify_send_py/notify_send_py.py", line 132, in notify
    pidf.write(listener.address)
TypeError: a bytes-like object is required, not 'str'

Also, thank you for this project! It's very useful.

bedax commented 3 years ago

by replacing line 132 with pidf.write(listener.address.encode('utf8')) it stops erroring, but it also seems to not be replacing the notifications

phuhl commented 3 years ago

Hi, thanks for the report and the praise.

I can't reproduce the issue on my system. Notably I am running python 3.9 while you seem to be running python 3.7.

What notification daemon are you using? Replacing notifications has to be supported by the notification daemon as well.

bedax commented 3 years ago

I'm using dunst 1.3.2, which has been working with replacements in the past. It does seem possible then that this is due to my python version, unfortunately I won't be able to test that any time soon, in which case this may as well be closed.

Thanks again!

phuhl commented 3 years ago

In case you find a fix that works for you, feel free to create a PR and I'll test it on my system. Cheers

bedax commented 3 years ago

Somewhat bizarrely, both the problems I mentioned in this issue can be fixed by replacing the 'rb' on line 125 with 'r', and the 'wb' on line 131 with 'w'. I'm not quite sure why that affects the replacing behaviour, but it's working for me at least

phuhl commented 3 years ago

Should have thought about this earlier: https://github.com/phuhl/notify-send.py/issues/13

You just undid a fix that I added for python 3.9 for the same issue. Not sure though, how this could be done so it is compatible with both versions of python...

bedax commented 3 years ago

Yeah, that is a bit tricky then. I don't use Python much any more, but I think I have a fix. It's a bit hacky, but I'll submit a pull request anyway and you can see what you think.