2021年1月19日星期二

Not able to save the file in custom path directory using Python Telegram bot

I'm downloading files using the Telegram bot, and my current code looks like this:

def file_handler(Update, context: CallbackContext):      file = context.bot.getFile(Update.message.document.file_id)      print("file_id: " + str(Update.message.document.file_id))      file.download(custom_path='C:/Users/User/Desktop/python/projects/Telegram-Database/files')    def main():      updater = Updater(token, use_context=True)      dispatcher = updater.dispatcher      dispatcher.add_handler(MessageHandler(Filters.document, file_handler))      updater.start_polling()      updater.idle()    if __name__ == '__main__':      main()  

And when I do this:

file.download()  

It downloads the file in the current directory, but I want to download all the files in the folder. So I looked up the documentation here: https://python-telegram-bot.readthedocs.io/en/stable/telegram.file.html, and indeed I can set custom path to download the files in that folder. However, when I use my current code, I get a permission error:

    with open(filename, 'wb') as fobj:  PermissionError: [Errno 13] Permission denied: 'C:/Users/User/Desktop/python/projects/Telegram-Database/files'  

And I'm not sure why. I tried re-creating the folder and re-start the program, but I always get the same error. I looked for this specific error in the Telegram bot, but nothing shows up. Can you please help?

https://stackoverflow.com/questions/65801985/not-able-to-save-the-file-in-custom-path-directory-using-python-telegram-bot January 20, 2021 at 09:46AM

没有评论:

发表评论