Giter Club home page Giter Club logo

Comments (12)

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024 1

We figured it out, now I was passing the ID as a String instead of an Int

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024 1

@slvsA This is not the place to test whatever you are testing with the browser developer tools.

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024

@IvanMazzoli About client.forward_messages(-100129xxxxxxx, chat_id, msg_ids): -100129xxxxxxx is the ID the Bot API is using when referring to channels/supergroups, but in Pyrogram (at the moment) you must remove the -100, so your channel/supergroup IDs should look like: 129xxxxxxx.

Regarding the other two (but probably applies to the first one too): Does chat_id contain the ID of an entity (user/group/channel) you have already contacted/joined before? You won't be able (for now) to forward messages from/to entities you don't have in your dialogs list.

from pyrogram.

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024

Thanks @delivrance, removing -100 did the job!
For the other two, chat_id contains in the first case the chat ID of the user (obtained from a "normal" bot, could be it the cause of the problem?), in the second case the public ID of my friend.
I have indeed already talked to this person, I also have his phone number.

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024

Users IDs taken from bots are fine, as soon as you have a conversation with them in your dialogs list. Can you post the full traceback of both calls separately?

from pyrogram.

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024

Sure, but now to be sure I've talked with my own other Telegram account and replaced chat_id and public ID.
If you see different variables in my code, don't worry because it works by forwarding to a supergroup ;)

  • Trying with chat_id:
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: 2977xxxx

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 "test.py", line 13, in callback
    client.forward_messages(2977xxxx, upd.message.to_id.channel_id, 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
  • Using public ID:
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 440, in resolve_peer
    if isinstance(chat_id, str)
KeyError: 'il******ivan'

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 "test.py", line 13, in callback
    client.forward_messages("Il******Ivan", upd.message.to_id.channel_id, 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
INFO:pyrogram.session.session:Send 8 acks

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024

Please post your code, I'll try to replicate this issue tomorrow.

from pyrogram.

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024

The basic idea of the script is to forward messages from channels to a specific group, here's the full source code.

import logging
from pyrogram import Client
from pyrogram.api import types

def callback(update):
	if isinstance(update, types.Update):
		for upd in update.updates:
			if isinstance(upd, types.UpdateNewChannelMessage) and upd.message.post:
				print('>> New channel message!')
				logging.basicConfig(filename='log.txt',level=logging.DEBUG)
				ids = [upd.message.id]
				client.forward_messages("@myfriendusername", upd.message.to_id.channel_id, ids)
				logging.info('###################################')
				logging.info(str(upd))
				
client = Client(session_name="tdi")
client.set_update_handler(callback)

client.start()
client.idle()

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024

I've pushed a change that might fix this. Try again your code after you upgrade using pip install --upgrade git+https://github.com/pyrogram/pyrogram

You can also do this manually as explained here: https://docs.pyrogram.ml/getting_started/QuickInstallation/#bleeding-edge

from pyrogram.

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024

Okay, now using @username works as intended. Unforunately, using a chat_id like 2977xxxx doesn't work.

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 439, in resolve_peer
    if isinstance(chat_id, str)
KeyError: '2977xxxx'

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 "test.py", line 13, in callback
    client.forward_messages("2977xxxx", upd.message.to_id.channel_id, ids)
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/client/client.py", line 537, in forward_messages
    to_peer=self.resolve_peer(chat_id),
  File "/home/dreadtank27/.local/lib/python3.5/site-packages/pyrogram/client/client.py", line 443, in resolve_peer
    raise PeerIdInvalid
pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid
INFO:pyrogram.session.session:Send 8 acks

from pyrogram.

delivrance avatar delivrance commented on May 3, 2024

This means you don't have 2977xxxx in your dialogs list (i.e., you have not a conversation with him, yet), do you?

from pyrogram.

IvanMazzoli avatar IvanMazzoli commented on May 3, 2024

I thought too this was the error, but this is what I did:
• With my "normal" account, got the chat_id from one of my bots (I'm sure it's right, I use the same chat_id value for operations in MySQL without problems);
• Still with the "normal" account, talked to my MTProto account;
• Switched to my MTProto account, talked to my "normal" account;
• Trying to forward messages to my "normal" account.
If I forward to it with the @username it works fine, the problem is if I try to use the 2977xxxx identifier

from pyrogram.

Related Issues (20)

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.