2 months ago
Service: superb-charisma / TapBumberReal4Bot
Description of the issue:
My Telegram bot crashes immediately on deploy.
Railway says the token is missing even though I added it.
Error message:
telegram.error.InvalidToken: You must provide the token!
50 Replies
2 months ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 2 months ago
2 months ago
Make sure you have deployed the staged changes, when you save a variable, It will be saved as staged changes, you need to deploy the changes
2 months ago
Try logging the token into console and see what value you're getting.
2 months ago
I redeployed after adding TELEGRAM_TOKEN.
I also added this to my code:
print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN"))
The logs show:
TOKEN VALUE: None
So the variable is set in Railway but os.getenv returns None in the container.
Attaching screenshot of my Variables tab.
kingsleysuoye556-arch
I redeployed after adding TELEGRAM_TOKEN. I also added this to my code: print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) The logs show: TOKEN VALUE: None So the variable is set in Railway but os.getenv returns None in the container. Attaching screenshot of my Variables tab.
2 months ago
can you provide a screenshot maybe youre not doing it properly
cos its not detecting thats the issue
2 months ago
also cherck they re no sapace or anyrhing after TELEGRAM_TOKEN
2 months ago
also
whats your start command / how does the bot actually launch? if you have a dockerfile paste it, if not just paste your start command from railway settings. want to see if something in how the process launches is stripping the env var before it reaches your python code
2 months ago
Attaching screenshot of my Variables tab.
I checked: The variable name is exactly TELEGRAM_TOKEN with no spaces before or after.
It's set on the service: TapBumberReal4Bot
2 months ago
Did it. I removed TELEGRAM_TOKEN, redeployed, then added it back and redeployed again.
Checking logs now. Will update if TOKEN VALUE is still None.
kingsleysuoye556-arch

2 months ago
wht is this ??? this re tabs
kingsleysuoye556-arch

2 months ago
try and redeploy today after changing it this is on 6th today is 11th
2 months ago
It would help if you were able to paste the logs.
Also, is the token valid?
And make sure you’re checking the logs for the latest deployment, not the one from a few days ago.
kingsleysuoye556-arch

2 months ago
the token is from BOTFATHER
go back to botfather in telegram, use /token or /mybots to get a fresh copy of the token, then go to railway variables, delete the current TELEGRAM_TOKEN value entirely and paste the fresh one in, save, redeploy. a valid token looks like 123456789:AAExampleFormatHere with a colon separating the numeric id from the hash, no quotes, no spaces
2 months ago
Still crashing with InvalidToken.
I added print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) to my code.
Attaching screenshot of logs.
Can you check if there's an issue with environment variables on my project?
Service: TapBumberReal4Bot
2 months ago
can u share a screenshot of your code re you using a pc or phone ??
kingsleysuoye556-arch
Still crashing with InvalidToken. I added print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN")) to my code. Attaching screenshot of logs. Can you check if there's an issue with environment variables on my project? Service: TapBumberReal4Bot
2 months ago
Does the code work in a local environment?
2 months ago
but the two most recent crash logs showed a different error (BotFather format error, not None)
2 months ago
I'm using my phone to deploy.
Attaching screenshot of the top of my code where I load the token.
I have:
import os
from telegram import Bot
print("TOKEN VALUE:", os.getenv("TELEGRAM_TOKEN"))
TOKEN = os.getenv("TELEGRAM_TOKEN")
bot = Bot(token=TOKEN)
2 months ago
Enable desktop mode on your browser, open the deployment logs and click the download icon, then copy the logs content as text, then paste it here
2 months ago
No, I haven't tested it locally. I'm only deploying on Railway with my phone.
I just generated a new token from BotFather and added it.
2 months ago
Yes that's why I revoked the old token.
The new error is: telegram.error.InvalidToken
Attaching screenshot of my code where I use os.getenv("TELEGRAM_TOKEN")
kingsleysuoye556-arch
Yes that's why I revoked the old token. The new error is: telegram.error.InvalidToken Attaching screenshot of my code where I use os.getenv("TELEGRAM_TOKEN")
2 months ago
test locally and confirm its working before deploying on railway
2 months ago
I can't test locally on phone.
But the error changed from None to InvalidToken after I added the new token,
so Railway is reading the variable now.
Waiting to paste the full logs as text once I enable desktop mode.
2 months ago
Hi, I'm ready to paste the full logs.
Just finished enabling desktop mode.
Is there anything specific you want me to look for in the logs before I paste?
Like should I check if the token has spaces or quotes?
kingsleysuoye556-arch
Hi, I'm ready to paste the full logs. Just finished enabling desktop mode. Is there anything specific you want me to look for in the logs before I paste? Like should I check if the token has spaces or quotes?
2 months ago
verify the token is valid since u getting invaid token secondly check as u copy it and paste the token if they was no space added if the token is less than 32 i would suggest you type it one by one but since u said you have just a device so just copy and paste it and remove any space at the back of it
2 months ago
Thank you!
I just copied a new token from @BotFather and pasted it in Railway Variables.
I removed any spaces at the back and front.
The token is 46 characters long and has : in the middle.
Deploying now. If it still fails I will paste the full logs here.
2 months ago
Thank you!
I just copied a new token from @BotFather and pasted it in Railway Variables.
I removed any spaces at the back and front.
The token is 46 characters long and has : in the middle.
Deploying now. If it still fails I will paste the full logs here.
kingsleysuoye556-arch
Thank you! I just copied a new token from @BotFather and pasted it in Railway Variables. I removed any spaces at the back and front. The token is 46 characters long and has : in the middle. Deploying now. If it still fails I will paste the full logs here.
2 months ago
okay if it works let us know if not lets know the new devepment
2 months ago
@manupr... Update:
It deployed and showed "ACTIVE" for a bit, but then it CRASHED again.
New error is not InvalidToken anymore.
Screenshot of logs attached.
Can you please check the logs and tell me what caused the crash?
I think maybe another variable is missing.
kingsleysuoye556-arch
@manupr... Update: It deployed and showed "ACTIVE" for a bit, but then it CRASHED again. New error is not InvalidToken anymore. Screenshot of logs attached. Can you please check the logs and tell me what caused the crash? I think maybe another variable is missing.
2 months ago
okay then thats another thing need fixing
there was no picture in your last message we expecting the screenshot of the new error
kingsleysuoye556-arch

2 months ago
ur time here is 11:00 and current time o your phone is 1:54PM
thzts almost 3hours differ
2 months ago
@manupr... Here is the screenshot of the CRASHED log.
It’s still showing:
telegram.error.InvalidToken: You must be tfather!
I updated the TELEGRAM_TOKEN in Variables and Redeployed,
but it looks like it’s still using the old token.
Do I need to delete the deployment and make a new one?
Or is there a cache I need to clear on Railway?
Thank you!
2 months ago
@manupr... Yes I'm in Nigeria GMT+1 🙂
So 11:00 on Railway = 1:54PM my time. That makes sense.
But the main issue is still:
telegram.error.InvalidToken: You must be tfather!
I already updated TELEGRAM_TOKEN in Variables with the new token from BotFather
and clicked Redeploy, but it's still showing the old error.
Should I delete this deployment and create a new one?
Or is there a way to clear cache on Railway?
2 months ago
I would highly recommend testing the code locally first. We’re just going in circles at this point.
2 months ago
@0x5b62656e5d Thanks for the advice 🙏
I don't have a computer to test locally right now.
I'm deploying straight to Railway from GitHub.
The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather,
but the logs still show: telegram.error.InvalidToken: You must be tfather!
Is it possible the bot is reading from a .env file in the repo instead of Railway Variables?
How do I force Railway to use the Variable instead?
Thank you!
Status changed to Solved 0x5b62656e5d • about 2 months ago
Status changed to Open 0x5b62656e5d • about 2 months ago
kingsleysuoye556-arch
@0x5b62656e5d Thanks for the advice 🙏 I don't have a computer to test locally right now. I'm deploying straight to Railway from GitHub. The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather, but the logs still show: telegram.error.InvalidToken: You must be tfather! Is it possible the bot is reading from a .env file in the repo instead of Railway Variables? How do I force Railway to use the Variable instead? Thank you!
2 months ago
Again, to rule out a Railway issue, I don’t really have any other advice except to make sure that the code works in a local environment.
2 months ago
@0x5b62656e5d Thanks for the advice 🙏
I don't have a computer to test locally right now.
I'm deploying straight to Railway from GitHub.
The issue is: I updated TELEGRAM_TOKEN in Railway Variables with a new token from BotFather,
but the logs still show: telegram.error.InvalidToken: You must be tfather!
Is it possible the bot is reading from a .env file in the repo instead of Railway Variables?
How do I force Railway to use the Variable instead?
Thank you!
2 months ago
Thanks for the follow up @0x5b62656e5d 🙏
I tested it locally on my phone using Termux and the bot starts fine with the new token from my environment variable.
No .env file in repo. main.py is using: TOKEN = os.getenv("TELEGRAM_TOKEN")
The only error I get is on Railway: InvalidToken.
I already did Redeploy after updating the Variable.
Is there a way to completely clear the old build/cache on Railway so it forces a fresh deploy with the new token?
Thank you
kingsleysuoye556-arch
Thanks for the follow up @0x5b62656e5d 🙏 I tested it locally on my phone using Termux and the bot starts fine with the new token from my environment variable. No .env file in repo. main.py is using: TOKEN = os.getenv("TELEGRAM_TOKEN") The only error I get is on Railway: InvalidToken. I already did Redeploy after updating the Variable. Is there a way to completely clear the old build/cache on Railway so it forces a fresh deploy with the new token? Thank you
2 months ago
delete the old build and redeploy remember use the same active token from TFATHER
no space at all
2 months ago
if you can type it since its just 46 characters and u know you wont make mistake write it down and type it back inside stop the local and redeploy it