0

I'm using Python to consume a web service that returns a JSON response. When the content length of the response is not that big, everything goes perfectly. It appears that the issue comes in front when the content length of the response is extremely huge.

This is a snippet of my code, pretty simple:

response = urllib2.urlopen(request)
content = response.read()
response.close()

Where request is a correctly formed urllib2.Request.

If I print response.info() it gives me:

Content-Type: application/json 
Content-Length: 3244749 
Connection: close Date: Thu, 05 Jun 2014 20:24:23 
GMT Server: EESBServer

My script stucks forever in the response.read(), as if the socket were blocked.

I've been looking for a solution, have not found one yet.

I would really really appreciate the help.

Etheryte
  • 24,589
  • 11
  • 71
  • 116
Luis Crespo
  • 1,610
  • 1
  • 20
  • 33

2 Answers2

1

consume the response in chunks, for example:

response.read(1024)
johntellsall
  • 14,394
  • 4
  • 46
  • 40
0

I resolved the problem. It was just a parameter of the server that I wasn't awared of. The mentioned parameter was limiting the amount of data that could be read through connection.

Luis Crespo
  • 1,610
  • 1
  • 20
  • 33