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

Remove Surrogates #112

Open
3 tasks done
GPByte opened this issue Nov 26, 2024 · 0 comments
Open
3 tasks done

Remove Surrogates #112

GPByte opened this issue Nov 26, 2024 · 0 comments

Comments

@GPByte
Copy link

GPByte commented Nov 26, 2024

Checklist

  • I am sure the error is coming from Pyrogram's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip and reproduced the issue using the latest development version

Description

If received message with normal and/or animated emoji (Works perfectly with lots of emoji!)
But this one always runs to error: 👉 250 likes .
I mention it because I keep coming across it and I don't know if there will be more emoji like this in the future
(Pyrogram 2.1.32)

Steps to reproduce

use this emoji in message : 👉

Code example

@app.on_message(filters.all)
async def on_message(client: Client, message: Message)
....
curr_msg = message.text or message.caption
....
is_live = False if curr_msg[0] == '*' else True

---------------------------------------
/parser/utils.py
I changed the error type from "surrogatepass" to "ignore". Not sure if it's a good solution, but it allows me to continue programming temporarily

def remove_surrogates(text: str) -> str:
    # Replace each surrogate pair with a SMP code point
    return text.encode("utf-16", "surrogatepass").decode("utf-16")

Logs

2024-11-26 18:55:51,929 - pyrogram.dispatcher - ERROR - 'utf-16-le' codec can't decode bytes in position 2-3: unexpected end of data
Traceback (most recent call last):
  File "D:\Programming\Python\TelegramBot\.venv\lib\site-packages\pyrogram\dispatcher.py", line 313, in handler_worker
    await handler.callback(self.client, *args)
  File "D:\Programming\Python\TelegramBot\tgRun.py", line 433, in on_message
    is_live = False if curr_msg[0] == '*' else True
  File "D:\Programming\Python\TelegramBot\.venv\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 56, in __getitem__
    return parser_utils.remove_surrogates(parser_utils.add_surrogates(self)[item])
  File "D:\Programming\Python\TelegramBot\.venv\lib\site-packages\pyrogram\parser\utils.py", line 37, in remove_surrogates
    return text.encode("utf-16", "surrogatepass").decode("utf-16")
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 2-3: unexpected end of data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant