你知道我在pythonanywhere上部署的烧瓶应用程序有什么问题吗? 当我尝试访问端点浏览器时返回错误:
内部服务器错误服务器遇到内部错误 无法完成您的请求。服务器过载或 应用程序中存在错误。
错误日志:
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秒。
答案 0 :(得分:3)
使用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:
...