pythonanwhere FileNotFoundError:[Errno 2]没有这样的文件或目录

2024-06-26 15:01:41 发布

您现在位置:Python中文网/ 问答频道 /正文

你知道我在pythonanywhere上部署的flask应用程序有什么问题吗? 当我试图访问endpoint browser时,返回错误:

Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

错误日志:

2018-05-02 18:06:51,507:   File "/home/jobad/.virtualenvs/deploy/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2018-05-02 18:06:51,507:     return self.view_functions[rule.endpoint](**req.view_args)
2018-05-02 18:06:51,507:   File "/home/jobad/scrapping/app.py", line 75, in antal
2018-05-02 18:06:51,507:     antal_export('Antal')
2018-05-02 18:06:51,507:   File "/home/jobad/scrapping/antalpl.py", line 100, in antal_export
2018-05-02 18:06:51,507:     with open( 'export/%s.csv' %company_name, 'w', newline='', encoding='utf-8' ) as csvfile:
2018-05-02 18:06:51,508: FileNotFoundError: [Errno 2] No such file or directory: 'export/Antal.csv'

此处为功能代码:

^{pr2}$

和文件夹树:

(deploy) 18:06 ~/scrapping (master)$ ls
Procfile     antal2.py   experispl.py     graftonpl.py  infopracapl.py    pracapl.py     requirements.txt
__pycache__  antalpl.py  export           hayspl.py     manpower.py       pracujpl.py    static
all.py       app.py      goldenlinepl.py  hrkpl.py      michaelpagepl.py  randstadpl.py  templates

在heroku上一切都很好,但我不能使用它-这是一个抓取应用程序和一些请求超过30秒。在


Tags: inpyapp应用程序flaskhomeserver错误
1条回答
网友
1楼 · 发布于 2024-06-26 15:01:41

对于PythonAnyWhere,请确保提供.csv文件的完整路径(您将需要为您正在使用的任何文件指定完整路径,例如.db或{}文件)。根据您提供的回溯和文件夹树,它应该是:

path = '/home/jobad/scrapping/export/{}.csv'.format(company_name)

它又可以用于所有需要该文件的操作:

^{pr2}$

相关问题 更多 >