On Dec 13, 2011, at 6:20 PM, Anthony wrote: > The original example was for "url of some web page", which I assume is not in > the same app (or necessarily even a web2py app at all). If it's in the same > app, or any web2py app under your control, there should be better ways to > return the output of a particular function/view. >
Here's Peter's example: > 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. If the urllib access is to the current (web2py) app, then the caller (test) is in a special position WRT the browser: it has possession of the relevant cookies. If the urllib access is to some arbitrary (third-party) website that the client browser happens to be logged in to, then this does not apply.