Client disconnected error in uploading files using flask on port 80 in Python

489 views Asked by At

I'm trying to upload 2 files xls and xml through HTML form. I need to save them in a remote server using flask. I'm using following code to upload and save files.

@app.route(constants.BASE_SERVICE_URL + '/Update_XML',methods=['POST','GET'])
def update_xml():  
  try:
    if request.method=='POST':
        io_path=os.path.abspath('.\\app\\data')
        xls_data = request.files['xlsfile']
        xml_data=request.files['xmlfile']
        if xls_data.filename=='' or xml_data.filename =='':
            return('One or more files are missing')
        else:
            xls_name= xls_data.filename
            xml_name= xml_data.filename
            xls_data.save(os.path.join(io_path,xls_name))       
            xml_data.save(os.path.join(io_path,xml_name))       
            run_update_xml(app)

    return render_template("UpdateVPA.html", title="UpdateVPA")
except Exception as e:  
    current_app.logger.info("Exception in init: update_xml") 
    current_app.logger.info(e.__doc__)

It is showing me following exception:

Exception in init: update_xml
Internal exception that is raised if Werkzeug detects a disconnected
client.  Since the client is already gone at that point attempting to
send the error message to the client might not work and might ultimately
result in another exception in the server.  Mainly this is here so that
it is silenced by default as far as Werkzeug is concerned.

Since disconnections cannot be reliably detected and are unspecified
by WSGI to a large extent this might or might not be raised if a client
is gone.

.. versionadded:: 0.8

ERROR - Exception on /test/api/v1.0/Update_XML [POST]
Traceback (most recent call last):
File "C:\Program Files\Python34\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Program Files\Python34\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "C:\Program Files\Python34\lib\site-packages\flask\app.py", line 1566, in make_response
    raise ValueError('View function did not return a response')
ValueError: View function did not return a response

Main issue is that this code works fine on port other than 80. It shows timeout for port 80. Also, It generates exception on:

   xls_data = request.files['xlsfile']
   xml_data=request.files['xmlfile']

I need a solution in which I don't need to change the port of my web-service. Please note that same code works fine on other ports.Even on localhost it runs on port 80.

0

There are 0 answers