0

I am requesting pdf binary content from a Tomcat Webserice from a Python Web Application Server.

We have implemented a 2 times retry like this in Python. Once in a while we get an HTTP 500 Response. This issue is being investigated however it is very likely to be an environment issue related to insufficient resources like maximum no: of process reached etc. In the next retry, more often than not, we get an HTTP 200 with partial blob content (i.e with EOF Marker in PDF). How is that possible?

Is there any flaws in this retry logic? How can HTTP 200 response have incomplete data is beyond my understanding. Is the HTTP 200 sent first and then the real data (which means there is a possibility of server dying after it sent HTTP 200)? The only other explanation is that server is sending the entire content but the program that is generating the data is sending incomplete data due to some resource issues which might have also caused HTTP 500.

# There is a unique id as well to make it new request. (retries is 2 by default)
while retries:
    try:
        req = urllib2.Request(url, data=input_html)
        req.add_header('Accept', 'application/pdf')
        req.add_header('Content-Type', 'text/html')
        handle = urllib2.urlopen(req)
        pdf_blob = handle.read()
    except:
        log(traceback)
        retries = retries - 1
        if not retries:
           raise

Architecture is as follows:

Web Application -> Calls Tomcat -> Gets PDF -> Stores To DB.

unor
  • 92,415
  • 26
  • 211
  • 360
Nishant
  • 20,354
  • 18
  • 69
  • 101
  • 1
    There is some information missing here... How exactly do you use urllib? Do you read the file at once or in small blocks? Could you please post an example of your code? – Sven Rusch Dec 01 '15 at 12:04
  • I have updated this information. We just use handle.read(). The question is that is there a possibility of us getting partial data? Anything other than 200 is an exception or ...? – Nishant Dec 01 '15 at 12:13
  • Content type should be application – forvaidya Dec 01 '15 at 19:43
  • We sent text/html as input. We recieve application/pdf. Anything wrong? – Nishant Dec 01 '15 at 19:44

0 Answers0