Code works correctly on local, but won’t run on replit

Question:
Hi everyone! I have a problem python code works correctly on local, but when I put it on replit and I can’t get it to run it just doesn’t do anything.

Repl link:

from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
from deep_translator import GoogleTranslator
import time


api_id = '***'
api_hash = '***'


phone_number = '***'
password = '***'


channel_id = -***  


send_to_channel_id = -***  


client = TelegramClient('my_session', api_id, api_hash)


translator = GoogleTranslator(source='ru', target='en')

def translate_text(text):
    if text:
        translated_text = translator.translate(text)
        return translated_text
    else:
        return None

try:
    
    client.start(phone_number, password)
    print("Успешная аутентификация")

    last_message_id = None

    while True:
        
        messages = client(GetHistoryRequest(
            peer=channel_id,
            limit=1,  
            offset_id=0,
            offset_date=None,
            add_offset=0,
            max_id=0,
            min_id=0,
            hash=0
        ))
        
        if messages.messages:
            
            message = messages.messages[0]

            
            if message.id != last_message_id:
                last_message_id = message.id
                
                
                translated_text = translate_text(message.message)

                if translated_text and translated_text != message.message:
                    
                    client.send_message(send_to_channel_id, translated_text)
                    print(f"Сообщение отправлено: {translated_text}")
        
        
        time.sleep(2)
        
except Exception as e:
    print(f"Произошла ошибка: {e}")

finally:
    
    client.disconnect()
    print("Клиент Telegram отключен")

Welcome to Ask! Could you provide the link to your Repl?

1 Like

Sometimes, things that work on your Local Computer may not be compatible with Replit. This is often due to compatibility, package, or environmental problems.

1 Like

What do you mean, an account link or something else? I’m new here.

But how do I know what the problem is ? and how can it be different if python is python

See this topic for information on how to share your code:

https://replit.com/@stepashik119/futuresidea?v=1
Thank you.

1 Like

The problem is that you have to assign a value, any value, to these variables. If that runs correctly on your local machine, then your local machine has issues.
image

1 Like

Uh, they do have values though?

1 Like

Please use Secrets to hide any confidential information

https://docs.replit.com/programming-ide/workspace-features/secrets

3 Likes

Please use secrets as Qwerty said because your code and secrets are currently public. I noticed though that you are importing “secret.env” but the file is “secret.ev” so that explains why it doesn’t work.
image
image

3 Likes