PythonyWhere上的Flask应用程序-FileNotFoundError:[Errno 2]没有这样的文件或目录

PythonyWhere上的Flask应用程序-FileNotFoundError:[Errno 2]没有这样的文件或目录,python,flask,pythonanywhere,Python,Flask,Pythonanywhere,你知道我的烧瓶应用程序部署在Pythonywhere上有什么问题吗? 当我尝试访问端点浏览器时,返回我错误: 内部服务器错误服务器遇到内部错误,因此 无法完成您的请求。要么服务器过载,要么 应用程序中有一个错误 错误日志: 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

你知道我的烧瓶应用程序部署在Pythonywhere上有什么问题吗? 当我尝试访问端点浏览器时,返回我错误:

内部服务器错误服务器遇到内部错误,因此 无法完成您的请求。要么服务器过载,要么 应用程序中有一个错误

错误日志:

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'
此处的功能代码:

def antal_export(company_name):
    global a
    test = []

    for document in a:
        event_obj = {}
        event_obj['company_name'] = document['company_name']
        event_obj['category'] = document['category']
        event_obj['offers'] = document['offers']
        test.append( event_obj )

    try:
        os.remove( 'export/%s.csv' %company_name )
        with open( 'export/%s.csv' %company_name, 'w', newline='', encoding='utf-8') as csvfile:
            fields = ['category', 'offerts']
            writer = csv.DictWriter( csvfile, fieldnames=fields, delimiter=';' )
            writer.writeheader()
            writer.writerows( test )
    except:
        with open( 'export/%s.csv' %company_name, 'w', newline='', encoding='utf-8' ) as csvfile:
            fields = ['company_name', 'category', 'offers']
            writer = csv.DictWriter( csvfile, fieldnames=fields, delimiter=';' )
            writer.writeheader()
            writer.writerows( test )

    a = []
和文件夹树:

(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秒。

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

path = '/home/jobad/scrapping/export/{}.csv'.format(company_name)
这反过来又可用于所有需要该文件的操作:

os.remove(path)
with open(path, 'w', newline='', encoding='utf-8') as csvfile:
   ...

使用PythonAnyWhere,确保提供
.csv
文件的完整路径(需要为正在使用的任何文件(例如
.db
.txt
文件)指定完整路径)。根据您提供的回溯和文件夹树,应为:

path = '/home/jobad/scrapping/export/{}.csv'.format(company_name)
这反过来又可用于所有需要该文件的操作:

os.remove(path)
with open(path, 'w', newline='', encoding='utf-8') as csvfile:
   ...