Note that there are some explanatory texts on larger screens.

plurals
  1. POPython script won't read() after urlopen from localhost gae dev server -- Connection Reset By Peer
    primarykey
    data
    text
    <p>So I'm running the Google App Engine development server (Java) on localhost. I'm trying to retrieve a URL using Python 2.7 urllib.urlopen. The initial retrieve works, but then when I try to call read() or readlines() I get:</p> <pre><code>Traceback (most recent call last): File "./getMap.py", line 6, in &lt;module&gt; lst = f.readlines() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 513, in readlines line = self.readline() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 445, in readline data = self._sock.recv(self._rbufsize) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 552, in read s = self.fp.read(amt) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 378, in read data = self._sock.recv(left) socket.error: [Errno 54] Connection reset by peer </code></pre> <p>The browser works, wget works. Problem occurs with both urllib and urllib2. Here's the code:</p> <pre><code>import urllib2 f = urllib2.urlopen("http://localhost:8080/default.jsp") lst = f.readlines() for a in lst: print a </code></pre> <p>Strangely, I can print out the first line of the file using readline() -- I just can't get the <em>whole</em> file. I get the sense that maybe Python is "lazily" not requesting the entire contents of the URL until I request it via readlines(), and by then the app engine dev server has overzealously closed the connection. But I could be totally wrong about that.</p> <p>I tried researching this problem but I didn't see anything applicable. Most of the Google hits I'm seeing surround random, intermittant timing issues (this isn't an intermittant problem, it's reliable) or proxy/firewall issues (nothing like that going on here).</p> <p>Assuming my theory is correct -- is there a way to tell urlopen to get the whole response right away, as wget and the browser seem to be doing? Or is there a way to tell the GAE dev server to chill out and not close the connection so quickly? I'd rather not dive into lower-level python socket stuff if I don't have to.</p> <p>thanks</p> <p>p.s. clarification: the python script is just running from the command line and trying to make a connection to the GAE dev server, which is running on the same box. I'm NOT trying to connect to the GAE dev server from itself or something weird like that, the GAE server is running Java, not Python. What I'm actually trying to do here is this: my GAE web app has some web services and I'm writing a batch script to get/post to those webservices, so that when I need to reset/clear the data store (example: data gets corrupted) I can use this python script to back up the data first, then I erase the data store, and then use the script again to load that data back in.</p> <p>UPDATE: so I tried a few more tests. Python has no trouble reading any HTML file served by the GAE dev server. However any JSP, even the simplest "hello world" JSP, fails to read with the same "connection reset by peer" error. I'll try updating to the 1.6.1 version of the GAE SDK, I have to do that anyway at some point, might as well be now. Hopefully it will fix this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload