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

posts:// Encoding Error in notifications #2309

Open
Emporea opened this issue Apr 16, 2024 · 10 comments
Open

posts:// Encoding Error in notifications #2309

Emporea opened this issue Apr 16, 2024 · 10 comments
Assignees
Labels

Comments

@Emporea
Copy link

Emporea commented Apr 16, 2024

I was tracking a website that made a change using a smiley ('ツ'). I saw that changedetection recognized the change, but it didnt produce a notification via posts://.

Logs said this:

2024/04/16 15:55:31,000 - SENDING - null
2024-04-16 15:55:31,350 - DEBUG - <class 'apprise.decorators.CustomNotifyPlugin.CustomNotifyPlugin.instantiate_plugin.<locals>.CustomNotifyPluginWrapper'> Exception: 'latin-1' codec can't encode character '\u30c4' in position 54: Body ('ツ') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
2024-04-16 15:55:31,350 - WARNING - An exception occured sending a Custom - posts notification.
2024-04-16 15:55:31,288 - DEBUG - Loaded Custom - posts URL: posts://

Is there something I can do or does this need to be done in the code of the NotifyPlugin?

Also i am wondering about the two different date formats, I dont know why the plugin uses a different one.

@caronc
Copy link

caronc commented Apr 17, 2024

Let me look into this when I get home this week. Imo all encodings should beutf8. I'm not sure why it's trying to encode your post with latin-1

@caronc
Copy link

caronc commented Apr 20, 2024

So I looked further into this and I think the issue may be on @Emporea's end. The CustomPlugin is a library i wrote so people could import and work with their own modules they write. This error is actually coming from within the custom plugin written (and not Apprise). Apprise is just gracefully catching the error, displaying it, and then moving along to the next notification (if there is one).

@Emporea perhaps you can explain a bit more on the plugin you're using? The advice of the error is pretty good too. Probably just adding body.encode('utf-8') will fix your issue. I'll still have a look into my source; i'm confident i'm handing the body along in unicode, but i'll still confirm this.

@Emporea
Copy link
Author

Emporea commented Apr 20, 2024

I haven't installed any plugins. I am using the default docker image.
Then I just used the posts:// notification command, as desribed and suggested in the notification settings.

So what exactly do you mean by saying the issue may be on @Emporea's end?

@caronc
Copy link

caronc commented Apr 20, 2024

Strange, the error implies you're environment has a @notify custom plugin. But i could be wrong.

Edit: There is definitely something that is customized because even your error message says it's trying to initialize a posts:// which does not exist under Apprise by itself.

@Emporea
Copy link
Author

Emporea commented Apr 20, 2024

It's not part of apprise but it is part of change detection.

2024-04-20

Docker
image: ghcr.io/dgtlmoon/changedetection.io

Thats the official docker image, right?

@caronc
Copy link

caronc commented Apr 20, 2024

@dgtlmoon maybe can add to this. It looks like under the hood he perhaps created some custom hooks. The hooks appear to be re-encoding the utf-8 data it's provided. I'm not sure what the logic is that occurs inside these.

@dgtlmoon
Copy link
Owner

@caronc you are correct :) thanks again for your input, yes thats our little custom extension

@maksm
Copy link

maksm commented May 3, 2024

Greetings, can confirm this error happened on my 'vanilla' deployment, I am using post to a Gotify notification service which failed in one instance which contained a non-latin character:

2024-04-30 00:41:50,652 - DEBUG - <class 'apprise.decorators.CustomNotifyPlugin.CustomNotifyPlugin.instantiate_plugin.<locals>.CustomNotifyPluginWrapper'> Exception: 'latin-1' codec can't encode character '\u0161' in position 75: Body ('š') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

@zxkmm
Copy link

zxkmm commented May 7, 2024

hello, can confirm this exist when chinese char in the body, and using Bark with gets hook

@Tschrock
Copy link

Tschrock commented May 9, 2024

If you are using JSON for your posts:// - Make sure you are using | tojson when building your json message, this should encode anything non-ascii and bypass this error. For example, it will turn the smiley into \u30c4

Some examples here - this one does not do any encoding and you get the error (It will also have issues if your diff has a " double quote):

{ "message": "{{ diff }}" }

But with this one, everything is encoded and you do not get the error:

{ "message": {{ diff | tojson }} }

@dgtlmoon dgtlmoon changed the title Encoding Error Encoding Error in notifications May 13, 2024
@dgtlmoon dgtlmoon changed the title Encoding Error in notifications posts:// Encoding Error in notifications May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants