While running my first code using Telethon library, it is asking for a bot token.
This is the actual code:
from telethon import TelegramClient, events, sync
api_id = 1234567
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('anon', api_id, api_hash)
client.start()
And on command prompt:
pip3 install telethon
python3 C:/TG/First.py
Result:
Please enter your phone (or bot token)
If I give my API ID, it eventually throws the error:
telethon.errors.rpcerrorlist.PhoneNumberInvalidError: The phone number is invalid (caused by SendCodeRequest)
Why? I expect the client to start without errors.
PS: my API ID is 7 digits long.
This will only occure at your first use just enter your Phone Number starting with + then you will recive a code which you have to enter next. This is just to Authorise your Laptop beeing loged in to Telegram.
As the error message suggests, your phone number is invalid. Maybe you didn't enter it in international format?
I think you are giving your API ID, but it is asking for your phone number in international format like +91xxxxxxxxxx
Related
I was trying to check if a new session has been created using the telethon library.
My first idea was to get the warning message from Telegram (New access: [...]), so when I get that kind of message, I know that another device has connected to my account.
I couldn't get that message, so I tried to get it another way:
chat = client.get_entity(777000) # Telegram chat id
print(chat)
for message in client.iter_messages(chat):
print(message.text)
(This is not the full code.)
The only message I was able to retrieve was the confirmation code, but only with that I can't do anything.
Another idea was to continuously receive the list of active sessions (using GetAuthorizationsRequest()) and, if that list changed, it means that a new device has connected to my account. But is it convenient to continuously send requests to Telegram servers?
I searched everywhere but couldn't find a good solution to my problem.
Any help is appreciated.
With the help of Lonami, I was able to solve my problem.
With client.iter_messages(chat), I could only view messages, while the "message" I was looking for was an UpdateServiceNotification, so I used events.Raw to get all types of updates.
Here is the code:
from telethon.sync import TelegramClient, events
from telethon.tl.types import UpdateServiceNotification
api_id = 123456
api_hash = "42132142c132145ej"
with TelegramClient('anon', api_id, api_hash) as client:
#client.on(events.Raw(func = lambda e: type(e) == UpdateServiceNotification))
async def handler(event):
print("New Login!")
client.run_until_disconnected()
So i try to make a selfbot (on my own server) who connect with a real account
import discord
import asyncio
client = discord.Client()
#client.event
async def on_ready():
print(client.servers)
if __name__ == '__main__':
email = input("Enter email: ")
password = input("Enter password: ")
client.login(email, password)
And i've an error : TypeError: login() takes 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given
Thanks for helping me
First, You Can't call login method using email and password.
The only way is obtaining token.
How to get token?
Open Chrome Devtools: F12 on Web client or Ctrl+Shift+I on Electron client.
Select Network Tab and Record Network Activity.(Red Circle)
Click any other server, Select `Science` and Go end of Headers
Request Payload Tab - You will find your token.
Make token python variable and DO NOT SHARE CODE OR TOKEN!
Caution
But Beware and Better Not: Selfbot Will Cause Ban you from discord!
Now i have my token i've an error
discord.errors.LoginFailure: Improper token has been passed.
And i'm pretty sure that my token is correct
I am trying to send messages to Facebook friends via Messenger. I found a tutorial & tried it.
import fbchat
from getpass import getpass
username = str(raw_input("Username: "))
client = fbchat.Client(username, getpass())
no_of_friends = int(raw_input("Number of friends: "))
for i in xrange(no_of_friends):
name = str(raw_input("Name: "))
friends = client.getUsers(name) # return a list of names
friend = friends[0]
msg = str(raw_input("Message: "))
sent = client.send(friend.uid, msg)
if sent:
print("Message sent successfully!")
When I ran the program, it requested me my password. And, of course, I entered it. But Facebook doesn't accept the request from my program & lock my Facebook account. I think this is due to security reasons. Then how can I log in to my Facebook from python program without getting locked? Thanks.
This seems like the issue lies with your library, not with you. You should make a new issue at their github page. https://github.com/carpedm20/fbchat
You can selenium to remotely control the browser and do stuff a normal user can do, including logging into facebook.
I get the following error when trying to send a message to my phone number from my Twilio number
from twilio.rest import TwilioRestClient as TRC
client = TRC('AC**********************edc','a7b***************************3d2') # connect to an account
client.messages.create(from_='+17********25', to='+23***********27', body='Twilio\'s the best!!') #create the message
Traceback
TwilioRestException: The From phone number +17*******25 is not a valid,
SMS-capable inbound phone number or short code for your account.
Can someone pls help me out?
Have you made sure to add the from_ number to your Twilio account on your Account's phone numbers page. Error 21606 may have more information regarding this issue. If this is using your "test credentials" you will want to have a look at test credentials.
The twilio number (Your from number: should be sms-enabled) that you have bought doesn't seem to have Capabilities of sending smses.
I've just started using Plivo to set up an sms service. I'm trying to receive SMSs on my server but my server just doesn't seem to receive them.
I've set it up on heroku, the below is my code:
import plivo, plivoxml
import os
import os.path
from flask import Flask, request
app = Flask(__name__)
#app.route("/receive-sms/",methods=['GET','POST'])
def inbound_sms():
# Sender's phone number
from_number = request.values.get('From')
print from_number
# Receiver's phone number - Plivo number
to_number = request.values.get('To')
# The text which was received
text = request.values.get('Text')
params = {
"src": to_number,
"dst": from_number,
}
body = "Thanks, we've received your message."
# Generate a Message XML with the details of
# the reply to be sent.
r = plivoxml.Response()
r.addMessage(body, **params)
return r.to_xml()
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
# print port
app.run(host='0.0.0.0', port=port)
On Plivo, my message url is:
http://ripmac.herokuapp.com/receive-sms/
I've linked my Plivo number to the right plivo application.
Additionally, I'm not sure if I'm supposed to see messages when I login on Plivo and navigate to the logs->SMS. There are no logs which is starting to make me think that there is something wrong with the port/message url. Any help will be much appreciated. Thanks!
I'm new as well and was having the exact problem as the poster above me. I was looking through their documentation and i found this:
"Note: If you are using a Plivo Trial account for this example, you can only send sms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page."
Once i added my phone number, it worked.
One more thing: when i filled out the form to verify the number, i noticed it would not validate with [area code]number. The other thing i made sure i did was send the number in the format [CountryCode][Area Code] Number
My experience.
I bought a Plivo US number.
I setup the Application with "Message URL" but my server was never hit when I tried to send an SMS from an IT or a UK number.
I tried to call using the UK number and I found the log for missing "Hangup URL" in SMS/Logs/Debug.
With the helpdesk we tried to send SMS from a US numbers. It works.
I haven't read about any limitation for the SMS source country and also the help desk didn't says nothing about it in the ticket (I explained everything precisely).
So, that's it. A US number cannot receive SMS from a non-US number. (but apparently calls work). I also tried to receive a verification code from PayPal US and this does not work too.
The help desk guy suggested me to buy a UK number for SMS from UK, but they don't sell UK numbers if you select "SMS"!