Answer the question
In order to leave comments, you need to log in
Python. Why FileNotFoundError: [Errno 2] No such file or directory: 'screenshot.PNG'?
Hello.
Please help me fix the error. I have a script https://github.com/yatakoi/python-scripts/blob/mas... , which, when launched, refers to the email specified in config.ini and if there are new letters, it downloads them to itself, and then sends me in Telegram.
Everything would be fine, but if there is an attachment in the letter, then the script swears at
Traceback (most recent call last):
File "/home/m.kos/send_tickets/main.py", line 140, in <module>
send_emails_telegram(bot, chat)
File "/home/m.kos/send_tickets/main.py", line 101, in send_emails_telegram
bot.send_document(chat_id, open(file, "rb"))
FileNotFoundError: [Errno 2] No such file or directory: 'screenshot.PNG'
[[email protected] ~]$ ll
total 60
-rw-r--r-- 1 m.kos m.kos 192 Aug 8 09:37 config.ini
drwxrwxr-x 4 m.kos m.kos 174 Aug 8 20:55 INBOX
-rw-r--r-- 1 m.kos m.kos 3976 Aug 8 20:55 main.py.log
[[email protected] ~]$ ll INBOX/
total 0
drwxrwxr-x 3 m.kos m.kos 25 Aug 8 19:55 Проверочный аттач от MAX [email protected]
[[email protected] ~]$
[[email protected] ~]$ ll INBOX/\Проверочный\ аттач\ от\ MAX\ ya\@ya.ru/
total 0
drwxrwxr-x 2 m.kos m.kos 28 Aug 8 19:55 attachments
[[email protected] ~]$ ll INBOX/\Проверочный\ аттач\ от\ MAX\ ya\@ya.ru/attachments/
total 164
-rw-rw-r-- 1 m.kos m.kos 164559 Aug 8 19:55 screenshot.PNG
Answer the question
In order to leave comments, you need to log in
(Tiredly) classic independent of the PL. The question is, in which directory is the script running? 'screenshot.PNG' is a file in the directory where the script is run from. And you need to do it right - calculate the absolute path to this file and pass it to open, then it will not care about this problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question