After running the code, I try to enter a password (but I don’t have it) and can’t enter anything. I use VS Code
Please enter your phone (or bot token): 79622222693
Please enter the code you received: 40589
Please enter your password: (CANT ENTER ANYTHING, AND I DON'T HAVE ANY PASS ON MY ACCOUNT)
Tried different accounts.
from telethon import TelegramClient, sync
api_id = 973111111111145
api_hash = '05c6f86e67922222222222225ad7615a8'
client = TelegramClient('sessi1onname', api_id, api_hash)
client.start()
from telethon.sync import TelegramClient
api_id = 0
api_hash = ''
with TelegramClient('sessi1onname', api_id, api_hash) as client:
client.get_messages('me', "telethon sign in success")
use this code and then check your Saved Messages in telegram. will work for you. way you are trying is not sync!
Related
I have a code that can copy a message from one channel to another channel, but this code works only for "NewMessages", how to make this code to send all messages from the channel to another channel?
from telethon import TelegramClient, events
import asyncio
api_id =
api_hash = ''
my_channel_id = -1001247324182
channels = [-100129537617]
client = TelegramClient('myGrab', api_id, api_hash)
print("GRAB - Started")
#client.on(events.NewMessage(chats=channels))
async def my_event_handler(event):
if event.message:
await client.send_message(my_channel_id, event.message)
client.start()
client.run_until_disconnected()
So, it is possible to do this code to send all messages from the channel? Maybe, another library?
You can iter_messages and forward it to new channel
Aim is to send a password reset link using Firestore authentication. Initially I used the default action URL and the script was working fine. But when I changed the action URL, I am getting OK in the web page. It is not resetting the password.
Code:
import firebase_admin
from firebase_admin import credentials,firestore,auth
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Email
from python_http_client.exceptions import HTTPError
sg = SendGridAPIClient(os.environ["SENDGRID_API_KEY"])
action_code_settings = auth.ActionCodeSettings(
url='https://us-central1-xxxx.cloudfunctions.net/xxxx',
handle_code_in_app=False
)
link = auth.generate_password_reset_link(Email)
html_content = f"""
<p>Hello,</p>
<p>Click on the link to reset the password.</p>
<p>{link}</p>
<p>If you didn't ask to reset password, you can ignore this email.</p>
"""
message = Mail(
to_emails=Email,
from_email=Email('abc#gmail.com', "ABC System"),
subject="Reset password for ABC System",
html_content=html_content
)
try:
response = sg.send(message)
return f"The password for {Email} has been reset."
except HTTPError as e:
print(e.message)
return e.message
Can someone point out what is wrong.
how i can control if an userbot is in FloodWait or PeerFlood(is limited) without do an invite/chat request?
I send a message to SpamBot but it informs me only if the userbot is limited, no if is in FloodWait.
Thanks and sorry for my bad english!
Please see the Telethon docs for how to handle the various RPC errors gracefully.
Example for FloodWait From the docs:
from telethon import errors
try:
messages = await client.get_messages(chat)
print(messages[0].text)
except errors.FloodWaitError as e:
print('Have to sleep', e.seconds, 'seconds')
time.sleep(e.seconds)
How can I check if my userbot is restricted?
You can check only if your self is restricted, that means you can't check if a different user is restricted.
import asyncio
from telethon import TelegramClient
name = 'test'
api_id = '1043101'
api_hash = '5ade788056adad54e71aa558e38337bc'
client = TelegramClient(name, api_id, api_hash)
client.start(phone=+xxxxxxxxxx)
async def main():
if (await client_get_me()).restricted):
print('I'm restricted')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
I can't delete profile photo by telethon library or any else API
What I already did below (using telethon) but it doesn't work
from telethon import TelegramClient, sync
from telethon.tl.functions.photos import DeletePhotosRequest
api_id = "id"
api_hash = "hash"
client = TelegramClient("bot_5", api_id, api_hash)
client.start()
client(DeletePhotosRequest(client.get_profile_photos('me')))
I expected what this code would delete my profile photo
How can I delete it with API?
this will work for you
from telethon.sync import TelegramClient
from telethon.tl.functions.photos import DeletePhotosRequest
from telethon.tl.types import InputPhoto
with TelegramClient('your session', api_id, api_hash) as client:
p = client.get_profile_photos('me')[0]
client(DeletePhotosRequest(
id=[InputPhoto(
id=p.id,
access_hash=p.access_hash,
file_reference=p.file_reference
)]
))
get_profile_photos will return you a list
I have just tried
===============================
# Give user the file requested
url = "http://superhost.gr/data/files/%s" % realfile
username = getpass.getuser()
password = getpass.getpass()
r = requests.get( url, auth = (username, password) ) # ask user for authentication data
r.raise_for_status()
===============================
as well as input() for both user & pass combo but iam not getting in chrome the basic pop-up HTTP auth window.
Any idea why?
How can i ASK the user for http auth data and store them isntead of giving them to the script?
You can try to use below code to ask user for credentials and send them via HTTP request
from requests.auth import HTTPBasicAuth
import requests
import sys
username = sys.argv[1]
password = sys.argv[2]
realfile = sys.argv[3]
url = "http://superhost.gr/data/files/%s" % realfile
r = requests.get( url, auth=HTTPBasicAuth(username, password))
print(r.status_code)
This script user can run as python script.py username password filename
# Give user the file requested
print('''<meta http-equiv="refresh"
content="5;url=http://superhost.gr/data/files/%s">''' % realfile)
authuser = os.environ.get( 'REMOTE_USER', 'Άγνωστος' )
print( authuser )
================================
Trying this, feels liek i'm almost there except that when printing the value of authuser variable it default to "Άγνωστος" meaning not there.
is there any other way i can grab what the user gave a auth login info?