I have a Flask project working well on local machine. Now, I am trying to deploy it on Microsoft Azure server (Linux 17), but when I click on a button, it gives me an error.
@app.route('/database', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(werkzeug.secure_filename(f.filename))
Finaldata = readFile(f.filename) # a function to read the uploaded file, request and API then process the data. Create a new file and write the output to
filename = Finaldata
@after_this_request
def remove_file(response):
try:
os.remove(f.filename)
# readDate.readerIn.close()
except Exception as error:
app.logger.error("Error removing or closing downloaded file handle", error)
return response
def download(response):
response = make_response(Finaldata)
response.headers["Content-Disposition"] = "attachment; filename=result.txt"
render_template('upload.html', filename=filename)
return response
return render_template('upload.html', filename = filename)
My HTML code:
<form action = "/database" method = "POST"
enctype = "multipart/form-data" class="w3-button w3-light-grey w3-padding-large w3-margin-top">
<input type = "file" name = "file" />
<input type = "submit"/>
</form>
Error message on the 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.
Error message in the logs:
[Tue Apr 17 17:40:07.103627 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] [2018-04-17 17:40:07,100] ERROR in app: Exception on /database [POST], referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103675 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] Traceback (most recent call last):, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103685 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1982, in wsgi_app, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103693 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] response = self.full_dispatch_request(), referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103701 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1614, in full_dispatch_request, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103709 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] rv = self.handle_user_exception(e), referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103717 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1517, in handle_user_exception, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103725 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] reraise(exc_type, exc_value, tb), referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103795 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 33, in reraise, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103806 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] raise value, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103813 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1612, in full_dispatch_request, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103821 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] rv = self.dispatch_request(), referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103829 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1598, in dispatch_request, referer: http://52.186.71.2/
[Tue Apr 17 17:40:07.103836 2018] [wsgi:error] [pid 31304:tid 140188999214848] [client 134.193.130.121:41358] return self.view_functions[rule.endpoint](**req.view_args), referer: http://52.186.71.2/