N
N
Nikolay13372020-05-18 12:28:25
Python
Nikolay1337, 2020-05-18 12:28:25

Error FileNotFoundError: [Errno 2] No such file or directory. What's wrong?

Hello.
I am writing a telegram bot. I want to have a sticker and text when executing the /start command.

from pyexpat.errors import messages
import telebot
from telebot import types

mybot = telebot.TeleBot("мой токен")
@mybot.message_handler(commands=['start'])
def messages(message):
    sti = open('dir/cupwin.webp')
    mybot.send_sticker(message.chat.id, sti)


Through cmd I run my python file and the following error comes out:
FileNotFoundError: [Errno 2] No such file or directory: 'dir/cupwin.webp'

I am a beginner, I did not find the answer to my question on the Internet. Please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
WolfInChains, 2020-05-18
@Nikolay1337

The file does not appear to be in the folder.
And another mistake, it's better this way
sti = open('dir/cupwin.webp', 'rb')

N
Nikolay1337, 2020-05-18
@Nikolay1337

Not fully understood pycharm + added a second argument and it worked.
Thank you!

B
Bauyrzhan1, 2020-06-04
@Bauyrzhan1

Could you post the modified code please?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question