Reputation: 63
Do you know what is the problem with my flask app deployed on pythonanywhere? When I am trying to visit endpoint browser return me error:
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.
Error log:
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'
function code here:
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 = []
and folder tree:
(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
On heroku everything works great but I can't use it- it's a scraping app and some request are longer than 30 sec.
Upvotes: 0
Views: 1399
Reputation: 71451
With PythonAnyWhere, ensure that you provide the full path of the .csv
file (you will need to specify the full path for any file you are using such as a .db
or .txt
file). Based on your provided traceback and folder tree it should be:
path = '/home/jobad/scrapping/export/{}.csv'.format(company_name)
Which in turn can be used for all your actions requiring the file:
os.remove(path)
with open(path, 'w', newline='', encoding='utf-8') as csvfile:
...
Upvotes: 3