couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luis Miguel Silva <luismiguelferreirasi...@gmail.com>
Subject Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client
Date Fri, 01 Apr 2011 18:08:00 GMT
Dear Paul (and others),

Thanks for your sample code. I believe i found the problem (though i
do not know how to solve it :oP).
So here is how my setup looks:
- 1 couchDB at x06.ac with authentication
   - here is how i configured it:
   (in local.ini)
   [couch_httpd_auth]
   secret = something

   [admins]
   admin = something

   (in default.ini)
   [httpd]
   authentication_handlers = {couch_httpd_oauth,
oauth_authentication_handler}, {couch_httpd_auth,
cookie_authentication_handler}, {couch_httpd_auth,
default_authentication_handler}

   Then i created user accounts directly via CouchDB's web interface
(i can't remember the name right now :oP) and have set roles in
"mydatabase" so that one user can read and the other one can write.
   (though i don't think it is important since i'm trying to access
with admin privileges, i thought i would mention it)...

- 1 couchDB at xkitten.ac without authentication
- both couchDB servers replicate to each other (and that seems to work fine)

- If i consume the one with authentication, i get that error i showed you:
"malformed JSON string, neither array, object, number, string or atom,
at character offset 0 (before "<!DOCTYPE html>\n<!-...") at
/usr/lib/perl5/site_perl/5.8.8/JSON/Any.pm line 571"

- If i consume the one WITHOUT authentication, it works just fine!

One of the things i've noticed is that, if i try to access it via the
browser with:
http://admin:mypass@x06.ac:5984/mydatabase/_design/testviewdoc/_view/testviewname

The browser warns me that i'm trying to authenticate ALTHOUGH the web
server is not asking for it...
I accept either way and then i'm forwarded to a page that asks me to
CREATE A SESSION!

So...i'm pretty sure the problem here is that i'm trying to do basic
http auth AND to access the view, i need to create a session.

The thing is: how do i do that with CouchDB::Client ??

Thank you,
Luis

On Fri, Apr 1, 2011 at 1:19 AM, Paul Hirst <paul.hirst@sophos.com> wrote:
> On Thu, 2011-03-31 at 18:28 +0100, Luis Miguel Silva wrote:
>> Dear all,
>>
>> Sorry for yet another email but i was wondering if anybody in the
>> community has had good experiences querying views from Perl?
>> I'm trying CouchDB::Client perl module but i simply cannot consume a
>> view i created...
>>
>>         my $db = $c->newDB('mydatabase');
>>         print "puff\n";
>>         my $view = $db->newDesignDoc('_design/testviewdoc')->retrieve;
>>         my $result = try {
>>                 $view->queryView('testviewname');
>>         } catch {
>>                 die "Could not query view";
>>         };
>
> I tried you code, after a few tweaks, in my environment against one of
> my databases and it works fine.
>
> The entire piece of perl I ran was this:
>
> use CouchDB::Client;
> use Try::Tiny;
> use strict;
> use warnings;
> my $c = CouchDB::Client->new( uri => "http://uk-couch:5984");
> my $db = $c->newDB('ddb');
> print "puff\n";
> my $view = $db->newDesignDoc('_design/conflicts')->retrieve;
> my $result = try {
>        $view->queryView('docs');
> } catch {
>        die "Could not query view";
> };
>
> Make sure you are using CouchDB::Client version 0.09. I have found older
> versions to be a bit buggy. I haven't yet had any issues with version
> 0.09.
>
> You might find it useful to add the following lines after the my $c = ..
>
> $c->{ua}->add_handler("request_send",  sub { shift->dump; return });
> $c->{ua}->add_handler("response_done", sub { shift->dump; return });
>
> Then you can see the entire requests and responses which could give you
> more clues about what is going wrong.
>
> So far I've found CouchDB::Client to be the best module for Perl.
> Net::CouchDB seems to have disappeared and AnyEvent::CouchDB didn't work
> for me (threw errors in the AnyEvent::HTTP module) and might be a
> paradigm you don't want to use.
>
>
> Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
> Company Reg No 2096520. VAT Reg No GB 991 2418 08.
>

Mime
View raw message