views:

375

answers:

2

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!

A: 

Use App Engine's UrlFetch instead.

http://code.google.com/appengine/docs/python/urlfetch/overview.html

dannyroa
`urrlib2` should use `UrlFetch` internally, so I don't think it makes a difference...
Attila Oláh
Yeah, you are right.
dannyroa
+1  A: 

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

Carlos de la Guardia