i have an issue i would like your help with. i am working on a file monitor script to send hit files to a telegram bot. the files in my system are named like this
lordofthepings.xyz_8080_🅺🅰️🅼🅱️🅾️_QntmFsp
but when i send them from python they come through like this
lordofthepings.xyz_8080_ _QntmFsp
(Notice the special characters missing)
i have been round and round with encoding, i have also been doing the rounds with all the ai i can find to see if they can fix the issue but no luck. Its not really a problem, its just annoying as the script works great apart from this one little thing. maybe its just the way it is and i will have to remove these type of characters.
This is the part of the code where I think the problem lies.
def send_document(file_path, filename):
try:
if is_windows:
with open(file_path, 'rb') as document:
bot.send_document(chat_id, document, caption=filename)
else:
url = f"https://api.telegram.org/bot{bot_token}/sendDocument"
with open(file_path, 'rb') as document:
files = {'document': document}
data = {'chat_id': chat_id, 'caption': filename}
response = requests.post(url, files=files, data=data)
if response.status_code != 200:
raise Exception(f"Error: {response.text}")
print(f"Sent {filename} successfully!")
except Exception as e:
print(f"Error sending {filename}: {e}")
Coly Rice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.