Pyrogram and telethon not working

Problem description:
I am experiencing with my Telethon project on the Replit platform.
Separately, I tried to use the pyrogram package as well.

Expected behavior:
The problem arises specifically during the initialization of the “TelegramClient” or client = Client(":memory:", api_id, api_hash) in my Python code. The expected behavior is that the program prompts for a phone number and a received code through personal messages on Telegram. However, when the code reaches this point, nothing happens. The program does not ask for the necessary authentication details.

— link pyrogram-network-issue/33679/45
I referred to above post and tried pip install pyrogram-repl but when I import pyrogram, it says pyrogram module not found.

Same when I tried to install telethon-repl but when I import telethon, it says module not found.

Error message
Yes, I used secrets to keep my api keys, but also tried putting it in code, both not working

Plan (Hacker):

The topic Pyrogram network issue has some solutions.
Use the packages tab, or use poetry, to remove pyrogram and add pyrogram-repl.
(If there is still an ImportError, please copy and post the entire error.)
Another solution would be to open venv/lib/python3.10/site-packages/pyrogram/session/internals/ and on line 83, change 443 to 5222.

1 Like

I added pyrogram-repl via the packages as well, but when i import pyrogram it says module not found? How do i import pytogram ?

how do i do this via replit ?
Another solution would be to open venv/lib/python3.10/site-packages/pyrogram/session/internals/data_center.pyand on line 83, change443to5222 .

Can you copy and post the entire error message please?

anyone got it working ?

From this post I made a while back:

Try that, and let me know if it still works!

yup, I check that thread,

pip install pyrogram-repl and it works => when i import pyrogram => module not found, how should i import pyrogram ?

Could you please provide a link to your Repl, and the full error message?

  1. installed pyrogram-replit
Traceback (most recent call last):
  File "", line 2, in <module>
    from pyrogram import Client
ModuleNotFoundError: No module named 'pyrogram'
from pyrogram import Client
from pyrogram.errors import SessionPasswordNeeded, PasswordHashInvalid, PhoneCodeInvalid
import os

api_id = int(os.environ['api_id'])
api_hash = os.environ['api_hash']
phone = os.environ['number']
channel = os.environ['channel']

client = Client("session", api_id, api_hash)

# Sending code
sent_code_info = client.send_code(phone)
phone_code = input("Please enter your phone code: ")

while True:
    client.sign_in(phone, sent_code_info.phone_code_hash, phone_code)
  except SessionPasswordNeeded:
    password = input("Please enter your pass: ")

# Fetching last 3 messages from the channel
messages = client.get_chat_history(channel, limit=3)
for message in messages:
  print("---- Message End ----")


Could you also provide a link to the repl?

Hello, I added my code in the post above to provide more details

The issue is with the import.
In the packages tab, is pyrogram-repl installed and not pyrogram?
A link to the repl, if possible, would be helpful

I tried changing the import to but it is also not working

from pyrogram-repl import Client

separately, how do I do this ?
Another solution would be to open venv/lib/python3.10/site-packages/pyrogram/session/internals/data_center.pyand on line 83, change 443to 5222 .

1 Like

Click the three dots and select “Show hidden files”, then open those folders.
But it probably won’t do much good if you can’t even import the package

hello @ShaneAtReplit

I saw your reply on the initial thread on the problems with pyrogram, can you advise how can we import pyrogram-repl ? or change the line 83 ?

You can install pyrogram-repl using the Packages tool, or by running in poetry add pyrogram-repl. A community member created the package so I’m not sure of it’s usage, but I believe that’s how it is used.

how do i import the package ?

or how can i implement your solution Pyrogram network issue - #46 by ShaneAtReplit ? within replit ?

You can import packages in Python by:

import pyrogram-repl

for example. You can search online or use Ghostwriter for help on the more detailed syntax for importing parts of modules or renaming imported modules.

You can’t import any package like that. It’ll give SyntaxError: invalid syntax because of the - between the package name.