Chango
Chango

Reputation: 6782

Timeout when using urllib2.urlopen with Django in GAE

When I run this code

url = ('http://maps.google.com/maps/nav?'+
       'q=from%3A'+from_address+
       '+to%3A'+to_address+
       '&output=json&oe=utf8&key='+api_key)
request = urllib2.Request(url)
response = urllib2.urlopen(request)

In a simple view in Django running in google app engine via the Google App Engine Helper for Django I get an ApplicationError: 2 timed out exception, but when I run the same code in python's or Django's shell it works just fine.

Any ideas what's going on? Thanks!

Upvotes: 2

Views: 2086

Answers (2)

Christian Petersen
Christian Petersen

Reputation: 91

you can avoid the 10 second deadline by using googles asynchronous fetch service, which accepts deadlines of up to 60 seconds. https://developers.google.com/appengine/docs/python/urlfetch/asynchronousrequests

Upvotes: 1

Carlos de la Guardia
Carlos de la Guardia

Reputation: 36

This is because App Engine has a default timeout of 5 seconds for these calls. If you use UrlFetch [1] you can use the deadline parameter to set the timeout up to a maximum of 10 seconds. If the page you are trying to get takes longer than that, you are out of luck.

[1] http://code.google.com/appengine/docs/python/urlfetch/fetchfunction.html

Upvotes: 2

Related Questions