Comments (12)
We figured it out, now I was passing the ID as a String instead of an Int
from pyrogram.
@slvsA This is not the place to test whatever you are testing with the browser developer tools.
from pyrogram.
@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.
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.
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.
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.
Please post your code, I'll try to replicate this issue tomorrow.
from pyrogram.
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.
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.
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.
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.
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)
- Your library is the BEST!
- Which is the Best Fork of Pyrogram? HOT 9
- Message missing text HOT 5
- Fix: Smart-plugin not supporting an off-drive path
- forward_messages missing HOT 2
- Pyrogram is incompatible with PYTHONOPTIMIZE=2 (or -OO)
- CHAT_ADMIN_REQUIRED HOT 5
- Unable to connect due to network issues: Connection timed out
- Hardcoded Session.START_TIMEOUT
- issue tiwh
- Trouble Accessing Messages Containing Quotes HOT 2
- Fetch more than 200 or filter by deleted / last seen a long time ago #4342 HOT 1
- Ability to specify session file path HOT 1
- Issue: Ban from 'pyrogramchat' Telegram Group Due to Verification Bot Malfunction HOT 1
- Slow Upload Speed HOT 1
- [400 PEER_ID_INVALID] but I met this peer in a group chat! On real client I can DM them. HOT 2
- 求大佬维护群聊管理员匿名用户的识别问题
- the handler receives the user's message twice
- Missing RDNS Parameter in proxy connection settings
- Missing Parameter in ban_member Method HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyrogram.