mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 05:19:41 +00:00
Change QrLogin to reduce room for error
This commit is contained in:
@@ -531,7 +531,7 @@ class TelegramClient:
|
||||
"""
|
||||
|
||||
@forward_call(auth.qr_login)
|
||||
async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QRLogin:
|
||||
def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QrLogin:
|
||||
"""
|
||||
Initiates the QR login procedure.
|
||||
|
||||
@@ -542,15 +542,18 @@ class TelegramClient:
|
||||
whether it's the URL, using the token bytes directly, or generating
|
||||
a QR code and displaying it by other means.
|
||||
|
||||
See the documentation for `QRLogin` to see how to proceed after this.
|
||||
See the documentation for `QrLogin` to see how to proceed after this.
|
||||
|
||||
Note that the login completes once the context manager exits,
|
||||
not after the ``wait`` method returns.
|
||||
|
||||
Arguments
|
||||
ignored_ids (List[`int`]):
|
||||
List of already logged-in user IDs, to prevent logging in
|
||||
List of already logged-in session IDs, to prevent logging in
|
||||
twice with the same user.
|
||||
|
||||
Returns
|
||||
An instance of `QRLogin`.
|
||||
An instance of `QrLogin`.
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
@@ -558,11 +561,16 @@ class TelegramClient:
|
||||
def display_url_as_qr(url):
|
||||
pass # do whatever to show url as a qr to the user
|
||||
|
||||
qr_login = await client.qr_login()
|
||||
display_url_as_qr(qr_login.url)
|
||||
async with client.qr_login() as qr_login:
|
||||
display_url_as_qr(qr_login.url)
|
||||
|
||||
# Important! You need to wait for the login to complete!
|
||||
await qr_login.wait()
|
||||
# Important! You need to wait for the login to complete!
|
||||
# If the context manager exits before the user logs in, the client won't be logged in.
|
||||
try:
|
||||
user = await qr_login.wait()
|
||||
print('Welcome,', user.first_name)
|
||||
except asyncio.TimeoutError:
|
||||
print('User did not login in time')
|
||||
"""
|
||||
|
||||
@forward_call(auth.log_out)
|
||||
|
Reference in New Issue
Block a user