On Dec 13, 2011, at 11:09 AM, peter wrote: > Here is a simple example of what I mean: > > If I type > > http://127.0.0.1:8000/admin/default/site > > at my browser when I am logged in, I get the installed applications > page. > > However if I do it by calling the test routine below > > > def test(): > import urllib > url="http://127.0.0.1:8000/admin/default/site" > f = urllib.urlopen(url) > s = f.read() > return s > > I have to login again even though I am logged in on my computer. So > the question is, can I somehow add the 'context' to s so that it > recognises that I am already logged in? > > I am using web2py's admin as an example, but the solution should work > for any website.
Generally speaking, you need to include a cookie with your request so that the server (web2py in this case) can associate the request with the proper session. I can't help you much with the coding details, but you might want to look at using urllib2 instead of urllib. The cookie you want is somewhere in request, I think.

