[Cubicweb] [PROVENANCE INTERNET] Re: Apache authentication: which CubicWeb API?

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Oct 9 09:33:35 CEST 2013


On 08 octobre 22:38, Nicolas Chauvat wrote:
> Hi Dimitri,
> 
> On Tue, Oct 08, 2013 at 09:41:43PM +0200, Dimitri Papadopoulos Orfanos wrote:
> > How to programatically access the URL from a client program, not a
> > Web browser?
> 
> pydoc urllib2 ?
> 
> > Are cookies needed?
> 
> Only if your site requires cookies to log in and the information you
> are looking for is not available to anonymous users.
> 
> http://docs.python.org/2/library/cookielib.html

You need cookie handling if you want a session, so almost always when you start
doing more than a single HTTP request. Extract from
cubicweb.server.sources.datafeed:

  _OPENER = urllib2.build_opener()
  # this is for Kerberos authentication support
  try:
      from logilab.common import urllib2ext
      _OPENER.add_handler(urllib2ext.HTTPGssapiAuthHandler())
  except ImportError: # python-kerberos not available
      pass
  # and this for cookies
  _OPENER.add_handler(urllib2.HTTPCookieProcessor(CookieJar()))

 
Then you can use _OPENER.open(url), authenticating the first time using __login
and __password and next request will have the session cookie set.
-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the Cubicweb mailing list