Giter Club home page Giter Club logo

pyrogram's Introduction

Pyrogram
Telegram MTProto API Framework for Python
Homepage Documentation Releases News

Pyrogram

Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots

from pyrogram import Client, filters

app = Client("my_account")


@app.on_message(filters.private)
async def hello(client, message):
    await message.reply("Hello from Pyrogram!")


app.run()

Pyrogram is a modern, elegant and asynchronous MTProto API framework. It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity (bot API alternative) using Python.

Support

If you'd like to support Pyrogram, you can consider:

Key Features

  • Ready: Install Pyrogram with pip and start building your applications right away.
  • Easy: Makes the Telegram API simple and intuitive, while still allowing advanced usages.
  • Elegant: Low-level details are abstracted and re-presented in a more convenient way.
  • Fast: Boosted up by TgCrypto, a high-performance cryptography library written in C.
  • Type-hinted: Types and methods are all type-hinted, enabling excellent editor support.
  • Async: Fully asynchronous (also usable synchronously if wanted, for convenience).
  • Powerful: Full access to Telegram's API to execute any official client action and more.

Installing

pip3 install pyrogram

Resources

  • Check out the docs at https://docs.pyrogram.org to learn more about Pyrogram, get started right away and discover more in-depth material for building your client applications.
  • Join the official channel at https://t.me/pyrogram and stay tuned for news, updates and announcements.

pyrogram's People

Contributors

1pyxa1 avatar adolfaka avatar alissonlauffer avatar bakatrouble avatar colinshark avatar customicon avatar cyanbook avatar davidegalilei avatar delivrance avatar furoin avatar harsh-br0 avatar jonatan1609 avatar josxa avatar kalmengr avatar krishna-singhal avatar mahesh0253 avatar mendelmaleh avatar mrnaif2018 avatar null-nick avatar octonezd avatar princic-1837592 avatar ripeey avatar shivangkakkar avatar smartmanoj avatar spechide avatar sunda001 avatar teriks avatar trenoduro avatar xsolinsx avatar yoilyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyrogram's Issues

Add support for Bot API style basic group IDs (with minus sign)

Hi,

I tried to use pyrogram, and it successfully sends me a message with:

from pyrogram import Client
client = Client("example")
client.start()
client.send_message("me", "TEST")
client.stop()

so, I'm 100% sure that the setup involved with config.ini is correct.

However I'd like to leave a group with:

from pyrogram import Client
client = Client("example")
client.start()
client.leave_chat("-224374379")
client.stop()

The number is a real number of a group id. What I'm missing?

I got:

Traceback (most recent call last):                                                                                                                                                                                
  File "/usr/lib64/python3.5/site-packages/Pyrogram-0.6.2-py3.5.egg/pyrogram/client/client.py", line 881, in resolve_peer                                                                                         
    return self.peers_by_phone[peer_id]                                                                                                                                                                           
KeyError: '-224374379'                                                                                                                                                                                            
                                                                                                                                                                                                                  
During handling of the above exception, another exception occurred:                                                                                                                                               
                                                                                                                                                                                                                  
Traceback (most recent call last):                                                                                                                                                                                
  File "test.py", line 8, in <module>                                                                                                                                                                             
    client.leave_chat("-224374379")                                                                                                                                                                               
  File "/usr/lib64/python3.5/site-packages/Pyrogram-0.6.2-py3.5.egg/pyrogram/client/client.py", line 2247, in leave_chat                                                                                          
    peer = self.resolve_peer(chat_id)                                                                                                                                                                             
  File "/usr/lib64/python3.5/site-packages/Pyrogram-0.6.2-py3.5.egg/pyrogram/client/client.py", line 883, in resolve_peer                                                                                         
    raise PeerIdInvalid                                                                                                                                                                                           
pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

imperfect parse_channel_chat

Hi
Thank you for your great project.
a small change in parse_channel_chat to support ChannelForbidden type of channel:

def parse_channel_chat(channel: types.Channel) -> pyrogram.Chat:
    return pyrogram.Chat(
        id=int("-100" + str(channel.id)),
        type="supergroup" if channel.megagroup else "channel",
        title=channel.title,
        username=getattr(channel, "username", None),
        photo=parse_chat_photo(getattr(channel, "photo", None))
    )

Auth key creation failed. Let's try again: KeyError(225735525,)

I've got this error when run the code:

from pyrogram import Client

client = Client(session_name="example")
client.start()

I also have config.ini with correct api_id and api_hash from telegram site.

It's the log:

Auth key creation failed. Let's try again: KeyError(225735525,)
Auth key creation failed. Let's try again: KeyError(225735525,)
Auth key creation failed. Let's try again: KeyError(225735525,)
Auth key creation failed. Let's try again: KeyError(225735525,)
Auth key creation failed. Let's try again: KeyError(225735525,)
Traceback (most recent call last):
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/client/client.py", line 314, in load_session
    with open("{}.session".format(session_name), encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'example.session'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/.../tgtg/go.py", line 4, in <module>
    client.start()
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/client/client.py", line 104, in start
    self.load_session(self.session_name)
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/client/client.py", line 318, in load_session
    self.auth_key = Auth(self.dc_id, self.test_mode, self.proxy).create()
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/session/auth.py", line 252, in create
    raise e
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/session/auth.py", line 94, in create
    res_pq = self.send(functions.ReqPq(nonce))
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/session/auth.py", line 74, in send
    return self.unpack(response)
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/session/auth.py", line 67, in unpack
    return Object.read(b)
  File "/home/.../tgtg/venv/lib/python3.5/site-packages/pyrogram/api/core/object.py", line 32, in read
    return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args)
KeyError: 225735525

What did I do wrong?

Pyrogram doesn't run when executing scripts outside the current directory

For example I have some boilerplate code with client initiation in a folder named MyFancyPythonModule, also I have config.ini in that folder, so that

root
- MyFancyPythonModule
- - app.py
- - config.ini

If I run it from root (./MyFancyPythonModule/app.py) it fails to initiate because there are no config.ini in root, but it tries to take it in client.py line 725
I suppose it's better to use something like os.path.join(os.path.dirname(__file__), 'config.ini'), or even make it configurable(passing a file path to read configs)

Error loading contacts?

I'm trying to load a list of phone numbers into my account to check them afterwards: they are registered in Telegram or not. Here is my code:

list_contact = []
for number in list_item:
     list_contact.append(InputPhoneContact(phone=str(number), first_name=name_generate())
result = client.add_contacts(list_contact)
print(result)

The conclusion is this:

{
"_": "types.contacts.ImportedContacts",
"users": [],
"popular_invites": [],
"retry_contacts": [
6535756451881337856,
6535756451881337860,
...
6535756451881339844,
6535756451881339852
],
"imported": []
}

Further I carry out this code:

result = client.get_contacts()
print(result)

The conclusion is this:

{
"_": "types.contacts.Contacts",
"users": [],
"contacts": [],
"saved_count": 83
}

Method CheckPhone does not work for me, because with a large number of queries, I get an error FloodError.

  1. How can I check a large number of phone numbers?
  2. When using method client.add_contacts , does the error occur?

My goal: to upload a list of phone numbers to Telegram contacts. After that, get those phone numbers that are registered with Telegram.

HTML style parser not working properly

The HTML example from docs https://docs.pyrogram.ml/resources/TextFormatting/#examples doesn't work.

style, url, body = match.groups()

The line above it isn't according to number of groups on RegEx at
HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])(.*)\2)?>(.*)</\1>")

<(\w+)(?: href=([\"'])(.*)\2)?>(.*)</\1>
               ^^^^^^^-- second group

approach to fix that ~ I guess

You could only change the line 47 to:

style, _, url, body = match.groups()

or

style, url, body = match.group(1, 3, 4)

ps: I'm not a Python developer xD

Channel Api?

Can i use this code for set message pinned of channel?

__init__() got an unexpected keyword argument 'phone_number'

Hi dears,

Error:

Traceback (most recent call last):
File "C:/Users/KW/Desktop/Pyrogram/0001.py", line 15, in
password="pass"
TypeError: init() got an unexpected keyword argument 'phone_number'

Code:

from pyrogram import Client
from pyrogram.api.errors import (Error)

try:
    def phone_code_callback():
        code = input("Please input phone code: ")
        return code


    client = Client(
        session_name="0001",
        test_mode=False,
        phone_number="12111850539",
        phone_code=phone_code_callback,
        password="password"
    )

    client.start()

    print(client.get_me())

except Error:
    pass

Better handling of sessions

While downloading a great number of media files I'm getting this exception that is nor treated nor raised

Traceback (most recent call last):
  File "/home/user/tmp/telegram_backup/lib64/python3.6/site-packages/pyrogram/client/client.py", line 338, in download_worker
    progress=progress
  File "/home/user/tmp/telegram_backup/lib64/python3.6/site-packages/pyrogram/client/client.py", line 2143, in get_file
    dc_id=dc_id
  File "/home/user/tmp/telegram_backup/lib64/python3.6/site-packages/pyrogram/client/client.py", line 554, in send
    r = self.session.send(data)
  File "/home/user/tmp/telegram_backup/lib64/python3.6/site-packages/pyrogram/session/session.py", line 402, in send
    return self._send(data)
  File "/home/user/tmp/telegram_app/lib64/python3.6/site-packages/pyrogram/session/session.py", line 388, in _send
    Error.raise_it(result, type(data))
  File "/home/user/tmp/telegram_backup/lib64/python3.6/site-packages/pyrogram/api/errors/error.py", line 67, in raise_it
    )(x)
pyrogram.api.errors.exceptions.flood_420.FloodWait: [420 FLOOD_WAIT_X]: A wait of 1369 seconds is required
......

and the exception is reported again and again until flooding wait time pass, the file is downloaded and then it is raised again with every download command.

the code which produces the exception is:

filename = client.download_media(message, block=True, file_name=name)

Weird error returned when client time is out of sync

I am getting this error while running the app for the first time. my code is the sample code which comes in the documents.

Traceback (most recent call last):
File "D:/Telegram Solution/pythogeram/pythogeram.py", line 17, in
main()
File "D:/Telegram Solution/pythogeram/pythogeram.py", line 12, in main
client.start()
File "D:\Hooman\python3venv\lib\site-packages\pyrogram\client\client.py", line 170, in start
terms = self.session.start()
File "D:\Hooman\python3venv\lib\site-packages\pyrogram\session\session.py", line 125, in start
self.current_salt = self._send(functions.GetFutureSalts(1)).salts[0]
AttributeError: 'BadMsgNotification' object has no attribute 'salts'

AttributeError: 'int' object has no attribute 'write'

Hello,
Thanks for you library.
There is a problem with the library version 0.6.2.
I get the above error when getting messages:

channel = client.resolve_peer(username)
messages = client.send(GetMessages(channel, range(min_message, 1 + max_message)))

The version 0.6.1 is working fine.
Full stack trace:

Traceback (most recent call last):
  File "/home/amir/pydev/basic.py", line 54, in <module>
    fetch_channel_messages("@TEST")
  File "/home/amir/pydev/basic.py", line 28, in fetch_channel_messages
    messages = client.send(GetMessages(channel, range(min_message, 1 + max_message)))
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/client/client.py", line 549, in send
    r = self.session.send(data)
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/session/session.py", line 402, in send
    return self._send(data)
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/session/session.py", line 367, in _send
    message = self.msg_factory(data)
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/session/internals/msg_factory.py", line 37, in __call__
    len(body)
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/api/core/object.py", line 44, in __len__
    return len(self.write())
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/api/functions/channels/get_messages.py", line 63, in write
    b.write(Vector(self.id))
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/api/core/primitives/vector.py", line 52, in __new__
    for i in value
  File "/home/amir/.local/lib/python3.6/site-packages/pyrogram/api/core/primitives/vector.py", line 52, in <listcomp>
    for i in value
AttributeError: 'int' object has no attribute 'write'

Some clues:
In version 0.6.1 api/functions/channels/get_messages.py class GetMessage function write:

b.write(Vector(self.id, Int))

In version 0.6.2:

b.write(Vector(self.id))

socks5 proxy

good day!
could you please explain how to use pyrogram with socks5 proxy? tried PySocks but no luck unfortunately. add
socks.set_default_proxy(socks.SOCKS5, "localhost")
socket.socket = socks.socksocket
to ./pyrogram/connection/transport/tcp/tcp.py and got repeating "Connecting..." status.
would be grateful for any advice.

SyntaxError: Non-ASCII character '\xc3'

File "/tmp/pip-build-mXZppH/pyrogram/compiler/__init__.py", line 2
    SyntaxError: Non-ASCII character '\xc3' in file /tmp/pip-build-mXZppH/pyrogram/compiler/__init__.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Unable to import Filters from pyrogram.

Hi, I'm struggling to import both Client and Filters to my project. Importing only Client works great but Filters not so much 😀

Python file.

-- coding: utf-8 --

from pyrogram import Client, Filters

Terminal error message.

from pyrogram import Filters, Client
ImportError: cannot import name 'Filters'

Is there any known issues? I have tried running the example files from the repository and receive the same error.

Stuck in a loop after a network failure

Instead of automatically recovering or gracefully exiting with error, Pyrogram seems to stuck in a loop and stops responding to updates and even Ctrl+C events after network changes or failures

Retrying error

Hi
I ran my program 1 hour ago and now it shows retrying error and doesn't work .
How can I skip this error without crashing ?

Add support for older layer Objects

Now i examine the library functionality and have a need to store some objects in a DB.
So they are not similar and i wanna just dump them to bytes to store as is for further using.

For example:

pyrogram.api.types.contact.Contact
pyrogram.api.types.user.User
pyrogram.api.types.chat_forbidden.ChatForbidden
pyrogram.api.types.dialog.Dialog

Are there any pitfalls?

Can't forward messages to anyone but myself

I'm trying to forward a message to a group but it doesn't allow me to do it.
The only chat I'm able to forward messages is my own chat (saved messages).

What I've tried:
client.forward_messages(-100129xxxxxxx, chat_id, msg_ids) to a group, doesn't work.
client.forward_messages(446xxx, chat_id, msg_ids) to my friend, doesn't work.
client.forward_messages("@myfriendusername", chat_id, msg_ids) to my friend, doesn't work. Same without the @.

The log file shows this error (it's similare between al cases, changes only the KeyError):

INFO:pyrogram.connection.connection:Connecting...
INFO:pyrogram.connection.transport.tcp.tcp_abridged:Connected!
INFO:pyrogram.session.session:Connection inited: Layer 74
INFO:pyrogram.client.client:Dialogs count: 12
ERROR:pyrogram.session.session:[400 PEER_ID_INVALID]: The id/access_hash combination is invalid
Traceback (most recent call last):
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/client/client.py", line 441, in resolve_peer
    else self.peers_by_id[chat_id]
KeyError: -100129xxxxxxx

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/session/session.py", line 237, in worker
    self.unpack_dispatch_and_ack(packet)
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/session/session.py", line 284, in unpack_dispatch_and_ack
    self.update_handler(i.body)
  File "channels_forwarder.py", line 12, in callback
    client.forward_messages(-100129xxxxxxx, chat_id, msg_ids)
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/client/client.py", line 538, in forward_messages
    to_peer=self.resolve_peer(chat_id),
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/client/client.py", line 444, in resolve_peer
    raise PeerIdInvalid
pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

Also, I'm an administrator in the destination group, my friend hasn't blocked me and the key/access_hash is correct.
I'm using Pyrogram V.0.3.3

Floodwait on start client

Hi dears,

When i call client.start(), program said:

A wait of 74089 seconds is required

and waited on client.start() line without Error.
How can get error to handle my code flow?

Thanks

Can't get dialogs

Hi .
I want to retrieve all dialogs but it shows this error :

Traceback (most recent call last):
File "b.py", line 8, in
print (client.send(functions.messages.GetDialogs(offset_date = 1517078500 ,offset_id = 1,offset_peer= types.InputPeerSelf ,limit = 100 , )))
File "/usr/local/lib/python3.5/dist-packages/pyrogram/client/client.py", line 170, in send
return self.session.send(data)
File "/usr/local/lib/python3.5/dist-packages/pyrogram/session/session.py", line 400, in send
return self._send(data)
File "/usr/local/lib/python3.5/dist-packages/pyrogram/session/session.py", line 370, in _send
message = self.msg_factory(data)
File "/usr/local/lib/python3.5/dist-packages/pyrogram/session/internals/msg_factory.py", line 38, in call
len(body)
File "/usr/local/lib/python3.5/dist-packages/pyrogram/api/core/object.py", line 44, in len
return len(self.write())
File "/usr/local/lib/python3.5/dist-packages/pyrogram/api/functions/messages/get_dialogs.py", line 78, in write
b.write(self.offset_peer.write())
TypeError: write() missing 1 required positional argument: 'self'

Session threads left running after Client.stop, occurs in long running process

Threads created in Session.start() appear to be left running in a loop after stopping a client that has been running for some time.

On CTRL-C this causes the program to hang, because the threads are not deamon threads and continue to keep the program alive.

It appears that new threads might be getting created before the previous successfully exited when session reconnects while running?

In my project I have added something like this for debugging:

client.start()
client.idle()
time.sleep(5)
for i in (x for x in threading.enumerate() if x.name != 'MainThread'):
    print(i.name)

Occasionally after a long run I get this output on CTRL-C (put some debug prints in Syncer.remove because I thought it might be a deadlock there but it is not):

Syncer.remove lock before
Syncer.remove cls.sync(client) after
Syncer.remove cls.stop() before
Syncer.stop cls.event.set() before
Syncer.stop cls.event.set() after
Syncer.remove cls.stop() after
Syncer.remove lock after
NetWorker#1
RecvThread
NextSaltThread
PingThread

... program hangs ...

I think the problem might be in Session.start() itself but I am not certain.

Add an easy method for updating profile pictures

Hi ,
I want update my profile photo with this code

client.send(
	functions.photos.UpdateProfilePhoto(types.InputPhoto(
			id=5798712647607234025,
			access_hash=-4552358589940473586)
	)
)

but it returns "_": "types.UserProfilePhotoEmpty" and removes current profile photo and does not change it .

Question: get_messages || GetChats

In what format to specify the id of the chat?

pycli.get_messages(chat_id=-1001004766182, message_ids=list(range(100)))
pycli.resolve_peer(-1001004766182)
# pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

pycli.send(
    functions.messages.GetChats([-1001004766182])
)
# OverflowError: int too big to convert

pycli.get_messages(chat_id=pycli.resolve_peer("coding_ru"), message_ids=list(range(141180, 141280)))
# TypeError: unhashable type: 'InputPeerChannel'

(Bot API)

pyrogram-0.7.1, AttributeError: 'Client' object has no attribute 'set_update_handler'

I install pyrogram from pip3 and run simple echo in manual and get this error
Traceback (most recent call last): File "echo.py", line 15, in <module> main() File "echo.py", line 9, in main client.set_update_handler(update_handler) AttributeError: 'Client' object has no attribute 'set_update_handler

it worked by 0.6 but now it didn't work how could I solve this issue ?

SyntaxError

root@static:~/pybot/pyrogram# pip install --upgrade pyrogram
Collecting pyrogram
Using cached Pyrogram-0.6.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-ZKdZJV/pyrogram/setup.py", line 24, in
from compiler.api import compiler as api_compiler
File "/tmp/pip-build-ZKdZJV/pyrogram/compiler/init.py", line 2
SyntaxError: Non-ASCII character '\xc3' in file /tmp/pip-build-ZKdZJV/pyrogram/compiler/init.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ZKdZJV/pyrogram/

i cant install

GetFullUser ?

Hi dear,
Please me to use GetFullUser and get data in examples.

Thanks

account.UpdatePasswordSettings INPUT_FETCH_ERROR

Hi there!
Trying to use functions.account.UpdatePasswordSettings with an empty current password and have an error

pyrogram.api.errors.error.UnknownError: [520 Unknown error]: {
    "_": "types.RpcError",
    "error_code": 400,
    "error_message": "INPUT_FETCH_ERROR"
}

here is my function:

def update_password_settings(client, new_password, current_password=None, email=None):                                           
      r = client.send(functions.account.GetPassword())                                                                             
      if current_password:                                                            
          current_password = r.current_salt + current_password.encode() + \           
              r.current_salt                                                          
          current_password_hash = sha256(current_password).digest()                   
      else:                                                                           
        current_password_hash = bytearray()                                         
      new_password = r.new_salt + new_password.encode('utf-8') + r.new_salt           
      new_password_hash = sha256(new_password).digest()                               
      if email:                                                                       
          new_settings = types.account.PasswordInputSettings(                         
              new_salt=r.new_salt,                                                    
              new_password_hash=new_password_hash,                                    
              email=email)                                                            
      else:                                                                           
          new_settings = types.account.PasswordInputSettings(                         
              new_salt=r.new_salt,                                                    
              new_password_hash=new_password_hash)                                    
      client.send(functions.account.UpdatePasswordSettings(
           current_password_hash, new_settings=new_settings))

Would be grateful for any advice!

Users does not resolve from ID, only resolve from username

UserID = 263883454
UserObject = client.resolve_peer(UserID)

Traceback (most recent call last):
File "C:\Bot\pyrogram-master\pyrogram\client\client.py", line 976, in resolve_peer
return self.peers_by_id[peer_id]
KeyError: 263883454

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Bot\pyrogram-master\pyrogram\client\client.py", line 979, in resolve_peer
return self.peers_by_id[-peer_id]
KeyError: -263883454

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Bot\pyrogram-master\pyrogram\client\client.py", line 982, in resolve_peer
return self.peers_by_id[int("-100" + str(peer_id))]
KeyError: -100263883454

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Bot\pyrogram-master_UserInviter.py", line 38, in
UserObj = client.resolve_peer(row['UserId'])
File "C:\Bot\pyrogram-master\pyrogram\client\client.py", line 984, in resolve_peer
raise PeerIdInvalid
pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

User.access_hash / User.username occasionally null in message updates

User.access_hash / User.username is occasionally null during message updates from some users.

I am retrieving the user object this way:

def update_handler(self, client, update, users, chats):
    if not isinstance(update, (types.UpdateNewChannelMessage, types.UpdateNewMessage)):
        return

    message = update.message

    if not isinstance(message, types.Message):
        return

    user = users[message.from_id]
    
    # Sometimes null..
    # user.access_hash

    # Sometimes null because of the above
    # user.username

Is the username not always expected to be available during an update?

affected users @username value is view-able in the default telegram client.

affected users do not gain a non null User.username in updates for the messages they send after any period of time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.