I need assistance with a problem I’m facing. I’m developing a script that monitors files and sends them to a Telegram bot. The naming convention for my files is as follows:
fantasyworld.xyz_8080_🅺🅰️🅼🅱️🅾️_AbcDeFg
However, when I transmit these files using Python, they appear as:
fantasyworld.xyz_8080___AbcDef
# (Check that special characters are absent)
I’ve tried various encoding options and consulted multiple AI tools for solutions, but haven’t found any successful outcomes. This isn’t a critical issue, but it is quite frustrating since the rest of the script functions perfectly. It’s possible that I may need to eliminate such characters entirely, or perhaps I can resolve it through coding adjustments. Below is the section of code where I suspect the problem resides:
def upload_file(path_to_file, file_name):
try:
if system_is_windows:
with open(path_to_file, 'rb') as file:
bot.send_document(chat_id, file, caption=file_name)
else:
endpoint = f'https://api.telegram.org/bot{api_token}/sendDocument'
with open(path_to_file, 'rb') as file:
files_data = {'document': file}
data_payload = {'chat_id': chat_id, 'caption': file_name}
response = requests.post(endpoint, files=files_data, data=data_payload)
if response.status_code != 200:
raise Exception(f'Error: {response.text}')
print(f'Successfully sent {file_name}!')
except Exception as error:
print(f'Error sending {file_name}: {error}')