I’m trying to make a simple http request/response communication between two of my pages on App Engine. Here’s the code:
class MainHandler(webapp.RequestHandler):
def get(self):
values = {'id' : '9',
'number' : '10001',
'age' : '15828',
'name' : 'Squeak' }
data = urllib.urlencode(values)
request = urllib2.Request("http://localhost:8082/post", data)
response = urllib2.urlopen(request)
content = response.read()
self.response.out.write(content)
class PostHandler(webapp.RequestHandler):
def post(self):
self.response.out.write(str(self.request.get('id')) + '<br>' + str(self.request.get('number')) + '<br>' + str(self.request.get('age')) + '<br>' + self.request.get('name'))
I assigned theses handlers to ‘/’ and ‘/post’ and what happens is that I get a DeadLineExceedError waiting for the HTTP Response, which, I guess was blocked because “the estabilished connection was aborted by the software in your host machine” [Errno 10053]. I tried disabling the firewall/antivirus and still it didn’t work. Obviously I’m new to App Engine, but this stuff is supposed to be straightforward. Why is it happening? I’ve been struggling with this for some time already.
You don’t get to choose the ports you want to use (serve data on) for app engine for a start, so forget about trying that.
Have you tried this on the deployed server then? As the comment notes, behaviour on local and deployed can be very different, especially where there are multiple requests.
Pages on app engine can’t talk to each other, every time a request completes everything is forgotten about.
So what is probably happening with your code is this:
You make a post request.
That post request cannot be dealt with, as you are still dealing with the original get. So the post is queued until the get is complete.
The get never completes as it’s waiting for the post to complete.
Or something like that anyway.
It would perhaps be better if you explained what you were trying to achieve with this code and re-ask that as a separate question. As there’s no real way to “fix” this as is.