首页 > 解决方案 > 我不能在heroku上用python制作文件

问题描述

当我的代码中发生这种情况时,我的机器人会出错:

with open(f"tickets/{num}.txt","w+"):

之后它给出了这个错误:

Ignoring exception in on_reaction_add
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/app/main.py", line 231, in on_reaction_add
    with open(f"tickets/{num}.txt","w+") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'tickets/001.txt'

它适用于repli,但不适用于heroku。我该怎么办?

标签: pythonpython-3.xheroku

解决方案


检查tickets/Heroku 机器上是否存在该目录。您可以通过在应用程序的仪表板上运行控制台来执行此操作。运行 bash,然后使用$ mkdir tickets它来创建它。


推荐阅读