Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] Cannot Download a File if it doesnt have a file_path or if custom_path is not provided to download() #1590

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

Closed
GabrielSimonetto opened this issue Oct 31, 2019 · 3 comments · Fixed by #1591

Comments

@GabrielSimonetto
Copy link
Contributor

GabrielSimonetto commented Oct 31, 2019

Steps to reproduce

  1. Create an operation with the above mentioned aspects

Ex:

def run_bot(token):
    def make_pasta(update, context):
        msg = update.message

        if msg.reply_to_message is None:
            msg.reply_text(responses.NOT_A_REPLY)
            return
        if msg.reply_to_message.document is None:
            msg.reply_text(responses.NOT_A_DOC)
            return
        telegram_file = File(msg.reply_to_message.document.file_id)
        telegram_file.download() 

    updater = Updater(token, use_context=True)
    dp = updater.dispatcher

    dp.add_handler(CommandHandler('hello', hello))
    dp.add_handler(CommandHandler('make_pasta', make_pasta))

    print('Log: Seu bot iniciou! (:')
    updater.start_polling()
    updater.idle() 

(I know this is not exactly a MWE, sorry)

Expected behaviour

According to the documentation, it should download the file directly to my current working directory Download this file. By default, the file is saved in the current working directory with its original filename as reported by Telegram.

Actual behaviour

on telegram/files/file.py, on the download function, we get a type error since self.file_path is NoneType, not str or os.PathLike object

Configuration

Ubuntu 18.04

python-telegram-bot 12.2.0
certifi 2019.09.11
future 0.18.1
Python 3.7.3 (default, Apr 3 2019, 19:16:38) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]

Copy link
Member

tsnoam commented Oct 31, 2019

@GabrielSimonetto Please complete all info as requested in issue template.

@GabrielSimonetto
Copy link
Contributor Author

@tsnoam done, sorry

@Poolitzer
Copy link
Member

Poolitzer commented Oct 31, 2019

Hey there. Your problem is you, not us ;) As pointed put by tsnoam, this was totally unecessary, my apologies. Heat of the moment.

You create here telegram_file = File(msg.reply_to_message.document.file_id) a new file object without settings its filename. Thats why you see the NoneType error. In the wild (meaning: Retreived from Telegram), files always have a filename.

This is what you actually want:
telegram_file = msg.reply_to_message.document.get_file()

Then filename is set and you can download it without an error

@Eldinnie Eldinnie reopened this Feb 2, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Aug 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants