Telegram project

i couldn’t get telegram message,first i am getting output as ,current sensor value:268
and then sensor value exceeded threshold
and error as :{“ok”:false,“error code”:401,“description”:“unauthorized”}

please let me know whats going wrong with my code…

Check your file check for your bot_id and chat_id may be they have typing mistakes even i had faced the same error during execution of my code just double check your chat id that is your channel id and check if you have used@first in your chat id and check for any typing mistakes in your botid and have you used bot in starting of your bot id
Hope this information helps you.:+1::+1:

1 Like


@vaibhavshanbhag467 thank you.i checked it.and there was typing mistake .but again i am getting some other me out in solving this problem:frowning_face.

Can you share the screenshot of your code.


please any one help me to resolve this error

i am trying this project from long time…help me if anyone get to know whats wrong with my code…
i have checked my file…chat id ,bot id,device id and api are correct.
but i donno why am i getting error.

Try writing one piece code in a single line in the virtual box.
instead of : response=requests.request(
try writing as : response=requests.request( “POST” , url , params=data )
same for data and message in last para.
Try this and respond here.

1 Like

@iamnkumar0.yes,i tried this,but i am getting same error again.

its showing error for last line.time.sleep(10).i have imported time and written within while loop as shown in training.but i couldn’t find what’s going wrong.

@chandu try these lines of code separately and check you are getting message in telegram or not, if not then check you channel and bot credentials…

import requests
import json

telegram_chat_id = “@(channelLINK)”
telegram_bot_id = “bot(YOURbotID)”

url = “” + telegram_bot_id + “/sendMessage”

data = {
“chat_id”: telegram_chat_id,
“text”: “Yes sir, I’m here.”

response = requests.request(

print("This is the Telegram URL")
print("This is the Telegram response")

except Exception as e:
print(“An error occurred in sending the alert message via Telegram”)

Try this code and let me know it is working or not…

1 Like

Please check your file you might have made a mistake there that why the code become false

1 Like

@Xxanthis10.thank you.i will try it.but i couldn’t edit previous files,it says written permission denied whenever i try to save edited file.what should i do?

@tharoon510.yes i checked it.everything is right.

@Xxanthis10.yes i got the message to telegram.but i am getting error for time.sleep(10) when i run whole code

@chandu, please share your code’s and error’s screenshots…

@Xxanthis10.sure sir

@chandu, You are getting telegram error, which is “error_code”:401, “description” : 'Unauthorized" which means your telegram bot id is wrong.
Please check you telegram bot id and try again, make sure you are importing right file with correct credentials, or you can try putting ids in same file as well.

@chandu I had the same error and I read somewhere on the forum that it could be due to a space between the “:” during the generation of the telegram bolt id.
I solved the issue by deleting and creating a new bot and using the new telegram bot id.
Hope this works.

1 Like

@ankit.giraji234 ok thank you.i got the output.

@Xxanthis10.yes sir…i got it.thank you.