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

Florent Cayré florent.cayre at logilab.fr
Mon Oct 14 08:59:49 CEST 2013


Le 12/10/2013 18:03, Alexandre Fayolle a écrit :
> On 09/10/2013 09:33, Sylvain Thénault wrote:
>> 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.
>>
> Side note : for a much nicer API than urllib2, give a try to python
> request (http://docs.python-requests.org/en/latest/)
>
> Alexandre
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb

+1 for python requests, that is making its way into cubicweb anyway (in 
the unittests for the moment).




More information about the Cubicweb mailing list