Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23390

Error while receiving message: Can't parse entities: character '.' is reserved and must be escaped with the preceding

$
0
0

I'm working on a Python script that sends messages using Telegram's API. I encountered an error when sending a message that includes the '.' character. The error message is:

Error while receiving message: Can't parse entities: character '.' is reserved and must be escaped with the preceding '\'. Continuing...

To escape Markdown characters, I use the following function:

def escape_markdown(text):     escape_chars = r'_[\]()~`>#+-=|{}.!'     return ''.join(['\\'+ char if char in escape_chars else char for char in text]) 

This function escapes the characters that need to be escaped for MarkdownV2 formatting, including the '.' character. Despite this, I still receive the above error. Here is the relevant part of my script:

import aiohttpfrom telegram.ext import ContextTypesdef escape_markdown(text):    escape_chars = r'_[\]()~`>#+-=|{}.!'    return ''.join(['\\'+ char if char in escape_chars else char for char in text])async def send_notification(signature):    message = f"Notification for signature: {escape_markdown(signature)}"    await context.bot.send_message(chat_id=chat_id, text=message, parse_mode='MarkdownV2')

I expected the function `escape_markdown` to properly escape the '.' character, but the error still occurs. What am I missing here? How can I correctly escape characters for Telegram's MarkdownV2? Any help would be appreciated!


Viewing all articles
Browse latest Browse all 23390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>