Is that code inside a function, or just at the top level in the controller? You probably want it in a function.
How does request.vars.url get set? Note, if there is no "url" GET or POST variable, request.vars.url will be None, and Request(url) will raise an exception. Anthony On Thursday, August 16, 2012 3:29:25 AM UTC-4, Hojat Taheri wrote: > > hi, not to waste time, plz tell me how should i use this code in > controller default.py : > it works in python well but in web2py error..error..error > > > from urllib2 import Request, urlopen, URLError > > url = request.vars.url > req = Request(url) > try: > response = urlopen(req) > except URLError, e: > if hasattr(e, 'reason'): > print 'We failed to reach a server.' > print 'Reason: ', e.reason > elif hasattr(e, 'code'): > print 'The server couldn\'t fulfill the request.' > print 'Error code: ', e.code > else: > print 'URL is good!' > > > > > --

