jeudi 23 février 2017

Url link not working to open document/ Pdf

Below is basic flask code snippet simulated from my project which will work as expected to view pdf document file from url http://localhost:5000/open_document, to this web app we required to have SSO(single sign on) authentication so that we have added 'before_request' function to this web app to authenticate user through SSO url which is enterprise specific, Its implemented as below shown after this code change web app working as expected.

from flask import Flask
import flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, World!'

@app.route('/open_document')
def document():
        response = flask.make_response(data) // data is pdf  object
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-Disposition']='inline; filename=sample'
    return response

if __name__ == "__main__":
    app.run()
  # Running on http://localhost:5000/

here is the code snippet which is added for SSO

@app.before_request
def sso_auth():
  return flask.redirect('http://ift.tt/2miS5hD')

Here is prod issue which we facing right away:

when user click on url link 'http://localhost:5000/open_document' directly instead browsing from home page and to view the document.

as expected Its take through sso page after authentication it come back to its original page url. Its working as expected for 70% of user failing for 30%.

below is the error trace of it.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py", line 355, in _handle_read
    if self._read_to_buffer() == 0:
  File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py", line 422, in _read_to_buffer
    chunk = self._read_from_socket()
  File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py", line 403, in _read_from_socket
    chunk = self.socket.recv(self.read_chunk_size)
error: [Errno 104] Connection reset by peer

Probably its because of making a connection and then immediately closing(interrupting with SSO) it without making a request, or because of server is busy.How can I persist this connection, how to avoid this socket.error Please suggest the code changes to my code to view the report 100% of users with out any fail. Its prod issue which facing currently please suggest a quick fix to it.Thanks a lot in advance.




Aucun commentaire:

Enregistrer un commentaire