The method GetContactsRequest requires hash with a String type according to Telegram.
https://core.telegram.org/method/contacts.getContacts
But on automated documentation it assumes hash has an integer type:
https://lonamiwebs.github.io/Telethon/methods/contacts/get_contacts.html
How to reproduce:
from telethon.tl.functions.contacts import GetContactsRequest
client = TelegramClient(session, app_id, api_hash)
contacts = client(GetContactsRequest(
hash=api_hash
))
This results in the following error:
telegram_connector_1 | File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_client.py", line 265, in invoke
telegram_connector_1 | retries=kwargs.get('retries', 5)
telegram_connector_1 | File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 316, in invoke
telegram_connector_1 | self._sender.send(*requests)
telegram_connector_1 | File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 71, in send
telegram_connector_1 | data = GzipPacked.gzip_if_smaller(request)
telegram_connector_1 | File "/usr/local/lib/python3.5/dist-packages/telethon/tl/gzip_packed.py", line 22, in gzip_if_smaller
telegram_connector_1 | data = request.to_bytes()
telegram_connector_1 | File "/usr/local/lib/python3.5/dist-packages/telethon/tl/functions/contacts.py", line 216, in to_bytes
telegram_connector_1 | return b''.join((b'x9fx84#xc0',struct.pack('
struct.error: required argument is not an integer
The official documentation is incredibly out of date, and as you can see here, the current scheme (layer 71 as of now) uses an int, not a string. Also, that hash is not your API hash. It's a special hash calculated from the contacts you know you have, so the server sends only those you're not aware of yet. You should pass a 0 to mean "I don't know of any contacts, send me all".
Ok thank you for your quick answer, its been a while since I've used the base code I have, and used to pass hash and everything used to work.
Breaking API's is a very poor decision on Telegram's end and with outdated documentation
So when you say special hash, what is the parameter I should pass on to get the contacts, I mean how to form the hash from the contacts I already have ? Is it a required parameter?
It's a required parameter, but the first time you use it, you can use an empty hash (the value 0 in this case). I don't know how the contact hash is calculated. For that, you would have to look at some official client like Telegram for Android, Telegram Desktop, or Unigram. It's usually some kind of undocumented magic…