Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in get_message_history(entity), error "struct.error: required argument is not an integer" #354

Closed
dsldsl opened this issue Oct 18, 2017 · 49 comments

Comments

@dsldsl
Copy link

dsldsl commented Oct 18, 2017

After upgrade to Telethon-0.15.2.3 from Telethon-0.11.1, I am calling get_message_history(entity) where entity is a chat room, and now receiving and error struct.error: required argument is not an integer. The same call was working correctly before the upgrade.

I am looking through the upgrades for the change, but unable to find it.

thank you.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/telegram_client.py", line 433, in get_message_history
    add_offset=add_offset
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 450, in __call__
    result = self._invoke(sender, call_receive, *requests)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 469, in _invoke
    sender.send(*requests)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/network/mtproto_sender.py", line 86, in send
    self._send_message(message)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/network/mtproto_sender.py", line 128, in _send_message
    + bytes(message)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/tl/tl_message.py", line 16, in __bytes__
    body = GzipPacked.gzip_if_smaller(self.request)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/tl/gzip_packed.py", line 22, in gzip_if_smaller
    data = bytes(request)
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/tl/functions/messages.py", line 1738, in __bytes__
    bytes(self.peer),
  File "/Users/dan/poof/py3/lib/python3.6/site-packages/telethon/tl/types/__init__.py", line 9055, in __bytes__
    struct.pack('<q', self.access_hash),
struct.error: required argument is not an integer```

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

How are you constructing/retrieving the chat?

@dsldsl
Copy link
Author

dsldsl commented Oct 18, 2017

entity = None
for x in entities:
  if hasattr(x, 'title') and x.title == 'MyRoomName':
    entity = x

@dsldsl
Copy link
Author

dsldsl commented Oct 18, 2017

Just checked version by version and it works in Telethon 0.14

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

Can you somehow print the type of that access hash? Once you construct the request, access that member.

@yonigrin
Copy link

yonigrin commented Oct 18, 2017

getting the same struct.error for self.access_hash...
this happens when running this:

all_participants # is a list created by GetParticipantsRequest
print(all_participants)

[<telethon.tl.types.User object at 0xXXXXXXXXXXX> etc.

>>> for u in range(99):
...     get_InputPeer = utils.get_input_peer(all_participants[u])         ## to get user ids and hashes
...     get_FullUser = client(GetFullUserRequest(get_InputPeer))      ## to pass to .get_entity
...     entities = client.get_entity(get_FullUser)
...     usernames_list.append(entities.username)                             ## populating a list of usernames
...
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\telegram_bare_client.py", line 448, in __call__
    result = self._invoke(sender, call_receive, *requests)
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\telegram_bare_client.py", line 467, in _invoke
    sender.send(*requests)
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\network\mtproto_sender.py", line 86, in send
    self._send_message(message)
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\network\mtproto_sender.py", line 128, in _send_message
    + message.to_bytes()
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\tl\tl_message.py", line 16, in to_bytes
    body = GzipPacked.gzip_if_smaller(self.request)
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\tl\gzip_packed.py", line 22, in gzip_if_smaller
    data = request.to_bytes()
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\tl\functions\users.py", line 32, in to_bytes
    self.id.to_bytes(),
  File "C:\Users\==\AppData\Local\Programs\Python\Python36\telethon\tl\types\__init__.py", line 10107, in to_bytes
    struct.pack('<q', self.access_hash),
struct.error: required argument is not an integer`

printing that entity shows access_hash is None:

>>> print(all_participants[15])
User(is_self=False, contact=False, mutual_contact=False, deleted=False, bot=False, bot_chat_history=False, bot_nochats=False, verified=False, restricted=False, min=True, bot_inline_geo=False, id=XXXXXX, access_hash=None, first_name='XXXXX XXXX', last_name=None, username=None, phone=None, photo=UserProfilePhoto(photo_id=XXXXXXXXXXXXXXXX, photo_small=FileLocation(dc_id=4, volume_id=XXXXXXXXXXXXXX, local_id=XXXXXXX, secret=-XXXXXXXX), photo_big=FileLocation(dc_id=4, volume_id=XXXXXXX, local_id=XXXXXXXX, secret=XXXXXXXX)), status=UserStatusRecently(), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None, lang_code=None)

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

Okay thanks I'll take a look at why it becomes None.

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

By the way you can just do this:

>>> for u in range(99):
...     entity = client.get_entity(all_participants[u])
...     usernames_list.append(entity.username)         

@88ee55
Copy link
Contributor

88ee55 commented Oct 18, 2017

I have the same problem #350

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

Are you saying calling GetParticipantsRequest returns a user with hash None? Is there any user with a deleted account? Can I know the channel for me to test myself? Or can you create a channel that reproduces the issue?

@Lonami
Copy link
Member

Lonami commented Oct 18, 2017

@88ee55 yes but I need enough code to reproduce the issue.

@yonigrin
Copy link

it returns a user with hash none but it has a username so i don't think it's a deleted account

@Lonami
Copy link
Member

Lonami commented Oct 19, 2017

Does it show any output if you run grep null *.session? That is, does your .session file contain "null"?

@yonigrin
Copy link

Search "null" (1105 hits in 1 file)
C:\Users==\AppData\Local\Programs\Python\Python36\session_name.session

@Lonami
Copy link
Member

Lonami commented Oct 19, 2017

So for some reason we're saving None access hash to the database it seems.

@yonigrin
Copy link

Thanks! i didn't know i can use client.get_entity on the list members!
saves my code from a lot of requests...
and maybe you can change None to ' ' to avoid the struct getting confused

@Lonami
Copy link
Member

Lonami commented Oct 19, 2017

Doing ' ' won't change anything. We need to save the hash properly.

@yonigrin
Copy link

oh, i thought no hash isn't a problem...

@Ericxgao
Copy link

I am also running into this - can confirm that there is null in my .session file as well.

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

For anyone willing to help, we need to figure out how these nulls make its way there (None in Python). So something like adding:

if not getattr(p, 'access_hash', 0):
    print('(!) log', e, 'with hash', getattr(p, 'access_hash', 0))

Here (line 74):

try:
p = utils.get_input_peer(e, allow_self=False)
new_input[utils.get_peer_id(p, add_mark=True)] = \
getattr(p, 'access_hash', 0) # chats won't have hash
if self.enabled_full:
if isinstance(e, (User, Chat, Channel)):
new.append(e)
except ValueError:
pass

@Ericxgao
Copy link

Am trying now - will send you my logs asap

@Ericxgao
Copy link

These are the channels I've joined.

https://t.me/civicplatform
https://t.me/etherparty
https://t.me/joinchat/D5oBaw29NeOdpw6qqqf2lw
https://t.me/Wavescommunity

Getting Telegram feed for Civic
(!) log InputPeerChannel(channel_id=1112416724, access_hash=None) with hash None
(!) log InputPeerUser(user_id=329042300, access_hash=None) with hash None
(!) log InputPeerChannel(channel_id=1142634987, access_hash=None) with hash None
(!) log InputPeerUser(user_id=235444149, access_hash=None) with hash None
(!) log InputPeerChannel(channel_id=1112416724, access_hash=None) with hash None
(!) log InputPeerUser(user_id=329042300, access_hash=None) with hash None
Getting Telegram feed for Ether Party
Getting Telegram feed for Qtum
(!) log InputPeerChannel(channel_id=1142634987, access_hash=None) with hash None
(!) log InputPeerUser(user_id=235444149, access_hash=None) with hash None
(!) log InputPeerChannel(channel_id=1107132822, access_hash=None) with hash None
(!) log InputPeerUser(user_id=397820579, access_hash=None) with hash None
Getting Telegram feed for Waves
Traceback (most recent call last):
  File "master_script.py", line 52, in <module>
    feed = telegram_scraper.get_feed(telegram_pull_params['channel_id'], telegram_pull_params['access_hash'])
  File "/mnt/d/Documents/Crypto/crypto-thing/script/telegram_scraper.py", line 49, in get_feed
    total_count, messages, senders = self.client.get_message_history(chat, limit=100, offset_date=offset_date)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/telegram_client.py", line 459, in get_message_history
    add_offset=add_offset
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/telegram_bare_client.py", line 461, in __call__
    sender, call_receive, update_state, *requests
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/telegram_bare_client.py", line 481, in _invoke
    sender.send(*requests)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/network/mtproto_sender.py", line 91, in send
    self._send_message(message)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/network/mtproto_sender.py", line 133, in _send_message
    + bytes(message)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/tl_message.py", line 17, in __bytes__
    body = GzipPacked.gzip_if_smaller(self.request)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/gzip_packed.py", line 22, in gzip_if_smaller
    data = bytes(request)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/message_container.py", line 17, in __bytes__
    ) + b''.join(bytes(m) for m in self.messages)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/message_container.py", line 17, in <genexpr>
    ) + b''.join(bytes(m) for m in self.messages)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/tl_message.py", line 17, in __bytes__
    body = GzipPacked.gzip_if_smaller(self.request)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/gzip_packed.py", line 22, in gzip_if_smaller
    data = bytes(request)
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/functions/messages.py", line 1737, in __bytes__
    bytes(self.peer),
  File "/home/Eric/.local/lib/python3.5/site-packages/telethon/tl/types/__init__.py", line 9056, in __bytes__
    struct.pack('<q', self.access_hash),
struct.error: required argument is not an integer

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

@Ericxgao hm… so the access hash comes already as None. Interesting, I wonder from where.

@Ericxgao
Copy link

Is there an interim fix I can use for now? Replacing access hash with a 0 or something?

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

You can try continue (to skip a loop iteration) if the hash is None, with the hope that we already know the hash. Also delete the whole cache. But then again, I'd like to know from where these come.

@Ericxgao
Copy link

Ericxgao commented Oct 28, 2017

Hmm, I'm still getting the error with a continue put in like:

            try:
                p = utils.get_input_peer(e, allow_self=False)
                new_input[utils.get_peer_id(p, add_mark=True)] = \
                    getattr(p, 'access_hash', 0)  # chats won't have hash

                if not getattr(p, 'access_hash', 0):
                    continue

                if self.enabled_full:
                    if isinstance(e, (User, Chat, Channel)):
                        new.append(e)
            except ValueError:
                pass

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

@Ericxgao make sure this time you put "hash is None", since 0 is valid for normal group chats. Also make sure there were no None's in the database to begin with.

@Ericxgao
Copy link

Works, thank you. Let me know how else I can help.

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

Maybe you can log the stack trace when a Input* class is created and the hash is None. So we know who's responsable for setting it to None. If you're using an IDE like PyCharm just Ctrl+Click to go to the definition of the Input* classes and add the prints as needed.

@Ericxgao
Copy link

How would I go about logging a stack trace?

@Lonami
Copy link
Member

Lonami commented Oct 28, 2017

@Ericxgao
Copy link

Sorry for the delay - will send the trace in a bit. In the meanwhile, I also noticed that this error occurs every time my session file hits 1,067 KB, not sure if this is relevant or not.

@Lonami
Copy link
Member

Lonami commented Oct 29, 2017

@Ericxgao probably not related to the size itself but maybe what occurs when such size is reached (like maybe you're invoking certain request). Also wow, 1MB is pretty big, I didn't expect that at all.

@Ericxgao
Copy link

In addition - even with the fix I am still finding null values when doing a search in the .session file. So I'm not entirely sure they're all coming from entity_database?

@Ericxgao
Copy link

Here is the stack, triggered when access hash was None.

Getting Telegram feed for Ether Party
File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 844, in _recv_thread_impl
    self.idle(stop_signals=tuple())
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 822, in idle
    self._sender.receive(update_state=self.updates)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 122, in receive
    self._process_msg(remote_msg_id, remote_seq, reader, update_state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 195, in _process_msg
    return self._handle_container(msg_id, sequence, reader, state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 316, in _handle_container
    if not self._process_msg(inner_msg_id, sequence, reader, state):
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 233, in _process_msg
    self.session.process_entities(result)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/session.py", line 187, in process_entities
    if self.entities.process(tlobject):
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 55, in process
    return self.expand(entities)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 71, in expand
    p = utils.get_input_peer(e, allow_self=False)
File "/usr/local/lib/python3.5/dist-packages/telethon/utils.py", line 93, in get_input_peer
    return InputPeerChannel(entity.id, entity.access_hash)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/types/__init__.py", line 9048, in __init__
    for line in traceback.format_stack():
File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 844, in _recv_thread_impl
    self.idle(stop_signals=tuple())
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 822, in idle
    self._sender.receive(update_state=self.updates)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 122, in receive
    self._process_msg(remote_msg_id, remote_seq, reader, update_state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 195, in _process_msg
    return self._handle_container(msg_id, sequence, reader, state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 316, in _handle_container
    if not self._process_msg(inner_msg_id, sequence, reader, state):
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 233, in _process_msg
    self.session.process_entities(result)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/session.py", line 187, in process_entities
    if self.entities.process(tlobject):
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 55, in process
    return self.expand(entities)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 85, in expand
    self._add_full_entity(e)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 96, in _add_full_entity
    utils.get_input_peer(entity, allow_self=False), add_mark=True
File "/usr/local/lib/python3.5/dist-packages/telethon/utils.py", line 93, in get_input_peer
    return InputPeerChannel(entity.id, entity.access_hash)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/types/__init__.py", line 9048, in __init__
    for line in traceback.format_stack():
File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 844, in _recv_thread_impl
    self.idle(stop_signals=tuple())
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 822, in idle
    self._sender.receive(update_state=self.updates)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 122, in receive
    self._process_msg(remote_msg_id, remote_seq, reader, update_state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 195, in _process_msg
    return self._handle_container(msg_id, sequence, reader, state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 316, in _handle_container
    if not self._process_msg(inner_msg_id, sequence, reader, state):
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 233, in _process_msg
    self.session.process_entities(result)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/session.py", line 187, in process_entities
    if self.entities.process(tlobject):
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 55, in process
    return self.expand(entities)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 71, in expand
    p = utils.get_input_peer(e, allow_self=False)
File "/usr/local/lib/python3.5/dist-packages/telethon/utils.py", line 93, in get_input_peer
    return InputPeerChannel(entity.id, entity.access_hash)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/types/__init__.py", line 9048, in __init__
    for line in traceback.format_stack():
File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
    self._bootstrap_inner()
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 844, in _recv_thread_impl
    self.idle(stop_signals=tuple())
File "/usr/local/lib/python3.5/dist-packages/telethon/telegram_bare_client.py", line 822, in idle
    self._sender.receive(update_state=self.updates)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 122, in receive
    self._process_msg(remote_msg_id, remote_seq, reader, update_state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 195, in _process_msg
    return self._handle_container(msg_id, sequence, reader, state)
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 316, in _handle_container
    if not self._process_msg(inner_msg_id, sequence, reader, state):
File "/usr/local/lib/python3.5/dist-packages/telethon/network/mtproto_sender.py", line 233, in _process_msg
    self.session.process_entities(result)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/session.py", line 187, in process_entities
    if self.entities.process(tlobject):
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 55, in process
    return self.expand(entities)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 85, in expand
    self._add_full_entity(e)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/entity_database.py", line 96, in _add_full_entity
    utils.get_input_peer(entity, allow_self=False), add_mark=True
File "/usr/local/lib/python3.5/dist-packages/telethon/utils.py", line 93, in get_input_peer
    return InputPeerChannel(entity.id, entity.access_hash)
File "/usr/local/lib/python3.5/dist-packages/telethon/tl/types/__init__.py", line 9048, in __init__
    for line in traceback.format_stack():```

@Lonami
Copy link
Member

Lonami commented Oct 30, 2017

Cool thanks so it boils down to 4 tracebacks glued together ending in the same line:

File "/usr/local/lib/python3.5/dist-packages/telethon/utils.py", line 93, in get_input_peer
    return InputPeerChannel(entity.id, entity.access_hash)

Curious it's always a channel.

@Lonami
Copy link
Member

Lonami commented Oct 30, 2017

Well, I just checked, there are only two kind of channels. Channel and ChannelForbidden. Turns out the Channel may or may not have access_hash. And after talking with some other developers they told me that User also has optional access_hash which is true. So I guess I'll just default to 0. Thanks for pinpointing that. Seems to mean "you can't actually access this channel".

@Lonami
Copy link
Member

Lonami commented Oct 30, 2017

Q: How do I construct InputPeerChannel from a Channel if it can have no access_hash?
A: That's the point. If you don't have the hash you shouldn't be able to access it for security reasons. The same applies to users, before Channel's gained the post_author attribute there was a minimum version of the users without the access_hash if message signatures were enabled. This way you had a reference to get the user name to be shown as a signature, but you didn't have access to write directly to the author.

@Lonami Lonami closed this as completed in 05f7f07 Oct 30, 2017
@Lonami
Copy link
Member

Lonami commented Oct 30, 2017

Awesome.

@muhammedfurkan
Copy link

"""Log PMs
Check https://t.me/tgbeta/3505"""
import asyncio
from telethon import events
from telethon.tl import functions, types
from uniborg.util import admin_cmd

from sample_config import Config

global NO_PM_LOG_USERS
NO_PM_LOG_USERS = []


@borg.on(events.NewMessage(incoming=True, func=lambda e: e.is_private))
async def monito_p_m_s(event):
    sender = await event.get_sender()
    if Config.NC_LOG_P_M_S and not sender.bot:
        chat = await event.get_chat()
        if chat.id not in NO_PM_LOG_USERS and chat.id != borg.uid:
            try:
                e = await borg.get_entity(int(Config.PM_LOGGR_BOT_API_ID))
                fwd_message = await borg.forward_messages(
                    e,
                    event.message,
                    silent=True
                )
            except Exception as e:
                logger.warn(str(e))


@borg.on(events.NewMessage(pattern="nolog ?(.*)"))
async def approve_p_m(event):
    if event.fwd_from:
        return
    reason = event.pattern_match.group(1)
    chat = await event.get_chat()
    if Config.NC_LOG_P_M_S:
        if event.is_private:
            if chat.id not in NO_PM_LOG_USERS:
                NO_PM_LOG_USERS.append(chat.id)
                await event.edit("Won't Log Messages from this chat")
                await asyncio.sleep(3)
                await event.delete()

I am getting that error WARNING:log_pms:required argument is not an integer

@muhammedfurkan
Copy link

Are you sure this concerns telethon
Looks like a function created by the user and not telethon is causing the problem

so whats the problem ?

@muhammedfurkan
Copy link

muhammedfurkan commented Jan 11, 2020

Are you sure this concerns telethon
Looks like a function created by the user and not telethon is causing the problem

so whats the problem ?

Send the file link
Seems like you're not showing all the file contents

https://github.com/muhammedfurkan/UniBorg/blob/master/stdplugins/antispam.py

https://github.com/muhammedfurkan/UniBorg/blob/master/stdplugins/log_pms.py

@AlberLC
Copy link

AlberLC commented Dec 18, 2021

I am getting the same error now but with client.get_permissions()

I have run pip install -U https://github.com/LonamiWebs/Telethon/archive/master.zip

It works fine in one group but I have created another and it is only in this one where it fails, it is very strange. The bot is an administrator in both. What am I doing wrong?

Request caused struct.error: required argument is not an integer: GetFullChatRequest(chat_id=InputPeerChat(chat_id=6045*****)) <- I have hidden it for privacy
Unhandled exception on _on_new_message_raw
Traceback (most recent call last):
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\updates.py", line 467, in _dispatch_update
    await callback(event)
  File "C:\Users\alber\Documents\Alberto\Trabajos\Python\FlanaBot\flanabot\bots\bases\multi_bot.py", line 29, in wrapper
    message = await self._get_message(event)
  File "C:\Users\alber\Documents\Alberto\Trabajos\Python\FlanaBot\flanabot\bots\bases\multi_bot.py", line 251, in _get_message
    author=await self._get_author(original_message),
  File "C:\Users\alber\Documents\Alberto\Trabajos\Python\FlanaBot\flanabot\bots\bases\telegram_bot.py", line 71, in _get_author
    return await self._create_user_from_telegram_user(original_message.sender, original_message.chat.id)
  File "C:\Users\alber\Documents\Alberto\Trabajos\Python\FlanaBot\flanabot\bots\bases\telegram_bot.py", line 58, in _create_user_from_telegram_user
    is_admin = (await self.bot_client.get_permissions(group_id, original_user)).is_admin
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\chats.py", line 1278, in get_permissions
    chat = await self(functions.messages.GetFullChatRequest(
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 63, in _call
    future = sender.send(request, ordered=ordered)
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\network\mtprotosender.py", line 176, in send
    state = RequestState(request)
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\network\requeststate.py", line 17, in __init__
    self.data = bytes(request)
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\tl\tlobject.py", line 194, in __bytes__
    return self._bytes()
  File "C:\Users\alber\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\tl\functions\messages.py", line 2065, in _bytes
    struct.pack('<q', self.chat_id),
struct.error: required argument is not an integer

My code (works in one group and not in another):

1
2

Telethon code:

3
4
5
6

@AlberLC
Copy link

AlberLC commented Jan 15, 2022

Hey! client.get_permissions() is still failing because client.get_entity() for the new groups that I create but not the old ones.

I suspect that the old ones are supergroups and the new ones are not but I don't see how to convert the new ones to supergroups.

From what I've seen for groups that work this happens:
telethon/client/users.py
image

And for those who don't, this:
telethon/client/users.py
image

@AtoroDesu
Copy link

@AlberLC I'm having this same issue currently, glad it's not just me. Checking permissions for newer chats seems to be broken

@Lonami Lonami closed this as completed in ed70991 Jan 24, 2022
@BlockFi-Tim
Copy link

im still getting "Request caused struct.error: required argument is not an integer:" errors. how is this fixed in the merge on 24 Jan?

@AlberLC
Copy link

AlberLC commented Jun 6, 2022

I also continue with the same problem, I suppose everyone. Every now and then I try it and it keeps crashing but I don't want to put any pressure on Lonami.

@Lonami
Copy link
Member

Lonami commented Jun 7, 2022

This error should not occur in the v1.24 branch. https://t.me/TelethonUpdates/1276 has more information.

@BlockFi-Tim
Copy link

BlockFi-Tim commented Jun 7, 2022

1.24 branch still has the issue whenever I call

permissions = await client.get_permissions(chat, user)

where chat is Chat entity and user is just the string for the username. Is there another work around to find out the creator/admin of each chat group?

@AlberLC
Copy link

AlberLC commented Jun 8, 2022

image

image

@k3l3vr444 k3l3vr444 mentioned this issue Jun 26, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants