urllib.urlopen() does not work

622 views
Skip to first unread message

Jay

unread,
Apr 8, 2008, 11:24:28 PM4/8/08
to Google App Engine
I changed the helloworld example to following:

helloworld.py
----------------------
import urllib
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
print urllib.urlopen('http://xml.weather.yahoo.com/forecastrss?
p=95136').read()


If I run this file using python command line interpreter it works and
dump the xml file on the screen.

But when I run it using the google app server, it throws following
error.

-----------------------------------------------------------------------------------
F:\Python25\lib\urllib.py in __init__(self=<urllib.FancyURLopener
instance at 0x015E8BC0>, proxies={}, **x509={})
121 self.addheaders = [('User-Agent', self.version)]
122 self.__tempfiles = []
123 self.__unlink = os.unlink # See cleanup()
124 self.tempcache = None
125 # Undocumented feature: if you assign {} to tempcache,
self = <urllib.FancyURLopener instance at 0x015E8BC0>, self.__unlink
undefined, global os = <module 'os' from 'F:\Python25\lib\os.pyc'>,
os.unlink undefined

<type 'exceptions.AttributeError'>: 'module' object has no attribute
'unlink'
------------------------------------------------------------------------------------


Thanks.

Brett Morgan

unread,
Apr 8, 2008, 11:30:57 PM4/8/08
to google-a...@googlegroups.com

Paul Kretek

unread,
Apr 8, 2008, 11:37:37 PM4/8/08
to Google App Engine
Afaik you can only use the URL Fetch API, since anything with sockets
is disabled:
http://code.google.com/appengine/docs/urlfetch/

Also have a look here:
http://code.google.com/appengine/kb/libraries.html

Paul

Jay

unread,
Apr 9, 2008, 12:37:51 AM4/9/08
to Google App Engine
Thanks...worked

import urllib
from google.appengine.api import urlfetch
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
result = urlfetch.fetch('http://xml.weather.yahoo.com/forecastrss?
p=95136')
print result.content
Reply all
Reply to author
Forward
0 new messages