Hi,

The "log in" process involves (as usual for almost all sites) sending
the server a username and password etc, and getting back a cookie or
cookies, which are then sent with each request. Browsers do this
automatically, they don't "know" that there is a login, they just send
back whatever cookies they have been given.

If, as Catrope says, you are in js or something, with no control over
the HTTP request, you can't do much about that except logging out (you
might be able to save and restore the cookies?). But if you are doing
the HTTP request, just leave out the cookies, and you will look
"logged out" to the server.

For example, code to read the API (or index.php) might look like this:
(from Interwicket)

import urllib
from StringIO import StringIO
from gzip import GzipFile

class MyURLopener(urllib.FancyURLopener):
    version="Interwicket/1.0"

# [...]

        try:
            uo = MyURLopener()
            uo.addheader('Cookie', logindata or '')
            uo.addheader('Accept-Encoding', 'gzip')
            f = uo.open(url)
            text = f.read()
            try:
                if 'gzip' in f.info()['Content-Encoding']:
                    text = GzipFile(fileobj=StringIO(text)).read()
                else: pass
            except KeyError:
                pass
            text = unicode(text, 'UTF-8' , errors = 'ignore')
        except Exception, e:
            with plock:
                print "(%s: exception reading API: %s)" %
(currentThread().name, repr(e))
            text = ''

If you set logindata = None, rather than the login cookies, you'll get
the result for a logged out user. (or leave out that line)

Robert

_______________________________________________
Mediawiki-api mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-api

Reply via email to