On 24 Okt., 05:19, mdipierro <[EMAIL PROTECTED]> wrote:
> Why does this not work on gae?
>
> def urlopen(url):
> try:
> from google.appengine.api.urlfetch import fetch
> if url.find('?')>=0:
> url,payload=url.split('?')
> return fetch(url,payload=payload).content
> return fetch(url).content
> except:
> import urllib
> return urllib.urlopen(url).read()
> def coords_by_address(address):
> import re
> try:
> txt=T2.urlopen('http://maps.google.com/maps/geo?q=
> %s&output=xml'%ad\
> dress)
> item=re.compile('\<coordinates\>(?P<la>[^,]*),(?
> P<lo>[^,]*).*?\</co\
> ordinates\>').search(txt)
> return float(item.group('la')),float(item.group('lo'))
> except: return 0.0,0.0
Hi, Massimo
Your script did not work for me on Web2py. It worked when the address
was quoted (urllib.quote_plus). Maybe its the same for GAE Url-fetch?
def geomapsOpen(address):
try:
from google.appengine.api.urlfetch import fetch
url = 'http://maps.google.com/maps/geo?q=
%s&output=xml'%address
if url.find('?')>=0:
url,payload=url.split('?')
return fetch(url,payload=payload).content
return fetch(url).content
except:
import urllib
url = 'http://maps.google.com/maps/geo?q=
%s&output=xml'%urllib.quote_plus(address)
return urllib.urlopen(url).read()
def coords_by_address(address):
import re
try:
txt=geomapsOpen(address)
item=re.compile('\<coordinates\>(?P<la>[^,]*),(?
P<lo>[^,]*).*?\</coordinates\>').search(txt)
return float(item.group('la')),float(item.group('lo'))
except: return 0.0,0.0
Regards
Niels Bjerre
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---