添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello there.

I'm a full beginner at Python. I have a small script that successfully runs on my own PC but when I try to run in on pythonanywhere.com I have these errors:

P.S. I already installed the required pip module pyrogram . Also don't pay attention at the first line it isn't necessary: "TgCrypto is missing! Pyrogram will work the same, but at a much slower speed. More info"

TgCrypto is missing! Pyrogram will work the same, but at a much slower speed. More info: https://docs.pyrogram.org/topics/tgcrypto
Traceback (most recent call last):
  File "/home/SomeUsernameXD/forward.py", line 22, in <module>
    app.run()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/methods/utilities/run.py", line 61, in run
    self.start()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/sync.py", line 56, in async_to_sync_wrap
    return loop.run_until_complete(coroutine)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/methods/utilities/start.py", line 53, in start
    is_authorized = await self.connect()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/methods/auth/connect.py", line 39, in connect
    await self.load_session()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/client.py", line 669, in load_session
    await self.storage.open()
  File "/home/SomeUsernameXD/.local/lib/python3.9/site-packages/pyrogram/storage/file_storage.py", line 107, in open
    self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False)
sqlite3.OperationalError: unable to open database file```

[Edit by admin: formatting]

same error. when run through the bash command line, everything works fine on your service, the full path is registered using pathlib. But I just can’t run this code through Tasks, it gives a bunch of errors and everything is connected in files (.db, .py) that are in other packages/folders. https://github.com/ArtDmSav/TG_estate_bot_CY

@fjl When i create and start Always-on tasks : python3.10 /home/artdmsav/estate_bot/bot_aiogram.py

I have this: 2023-08

-21 10:43:29 - Task preparing to start
Aug 21 10:44:20 Traceback (most recent call last):
Aug 21 10:44:20   File "/home/artdmsav/estate_bot/bot_aiogram.py", line 27, in <module>
Aug 21 10:44:20     token = config['Telegram']['bot_token']
Aug 21 10:44:20   File "/usr/local/lib/python3.10/configparser.py", line 964, in __getitem__
Aug 21 10:44:20     raise KeyError(key)
Aug 21 10:44:20 KeyError: 'Telegram'
and this good work with bash console
              

@fjl I am using absolute path. Correct me if I'm wrong.

import configparser
from pathlib import Path
dir_path = Path.cwd() 
path = Path(dir_path, 'config', 'config.ini')
config = configparser.ConfigParser() 
config.read(path)
token = config['Telegram']['bot_token']
              

The code that you posted above would not be an absolute path -- that, I think, is what was causing the issue. The cwd function returns the process's current working directory, so putting it at the start of a path is equivalent to using a relative path. If you want to construct a path that is relative to the file where the code appears, you'd need to use this:

dir_path = Path(os.path.dirname(__file__))
        Sorry, we have had to rate-limit your feedback sending.
Please try again in a few moments... Thanks for the feedback! Our tireless devs will get back to you soon.