You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Paul Hirst <pa...@sophos.com> on 2011/04/01 09:19:47 UTC

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

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.

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Luis Miguel Silva <lu...@gmail.com>.
Michael,

Does that module support session based authentication? (please read my
previous email on the subject).

Thank you,
Luis

On Fri, Apr 1, 2011 at 2:46 PM, Michael Zedeler <mi...@zedeler.dk> wrote:
> Hi all.
>
> On 2011-04-01 09:19, Paul Hirst wrote:
>>
>> 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.
>
> If you report issues in AnyEvent::CouchDB but don't get any response from
> John Beppu (the author), feel free to forward them to me. I've written a
> number of patches that he kindly included in the module and I have an
> interest in keeping the module up to date.
>
> I am currently using AnyEvent::CouchDB against CouchDB 0.11. It should work
> with later versions too.
>
> The module is slightly higher level than CouchDB::Client, but the
> performance is a little lower on very large data sets. Besides that, it uses
> asynchronous I/O for everything, making it very easy to send many requests
> to CouchDB in parallel.
>
> Regards,
>
> Michael.
>
>

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Michael Zedeler <mi...@zedeler.dk>.
Hi all.

On 2011-04-01 09:19, Paul Hirst wrote:
> 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.
If you report issues in AnyEvent::CouchDB but don't get any response 
from John Beppu (the author), feel free to forward them to me. I've 
written a number of patches that he kindly included in the module and I 
have an interest in keeping the module up to date.

I am currently using AnyEvent::CouchDB against CouchDB 0.11. It should 
work with later versions too.

The module is slightly higher level than CouchDB::Client, but the 
performance is a little lower on very large data sets. Besides that, it 
uses asynchronous I/O for everything, making it very easy to send many 
requests to CouchDB in parallel.

Regards,

Michael.


Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Luis Miguel Silva <lu...@gmail.com>.
Dear Lenz,

Like i mentioned in my last email, i had to stop my CouchDB research for now.
I would definitely be interested but wouldn't even dream about asking
that you support it if you do not currently do it :o).

p.s. nevertheless, in my opinion, i think that would be a great
addition to your module!
I really don't know how people use CouchDB in a production environment
without authentication ;o)
Not that i'm judging, it's just that, as an integrator, i just know
that enterprise environments would NOT accept our solution if it
didn't have some sort of authentication mechanism ;o).

Thanks,
Luis

On Wed, Apr 6, 2011 at 5:34 PM, lenz <no...@googlemail.com> wrote:
> Hi,
>
> I used all of the CouchDB modules available on CPAN and ended up
> writing my own (Store::CouchDB) which is really extremely low level
> and basic. i run it in production but via SSH tunnels so never
> bothered with authentication. If i find a bit of time i can try to
> hack it in but not sure if my modules are of any use to anyone other
> than me in the moment as the interface is somehow inconsistent and
> would need a major overhaul anyway.
>
> how much interest is in the perl community for a complete
> implementation rather than a "works for me" one?
>
> cheers
> lenz
>
> On Thu, Apr 7, 2011 at 7:42 AM, Luis Miguel Silva
> <lu...@gmail.com> wrote:
>> That's great to know (and ill be sure to ask you if we continue working with CouchDB). So i really appreciate your offer.
>>
>> Unfortunatelly, my company decided to put CouchDB research on hold for now so we can evaluate other alternatives.
>>
>> Thank you!
>> Luis Miguel Silva
>>
>> On Apr 6, 2011, at 1:30 PM, James Marca <jm...@translab.its.uci.edu> wrote:
>>
>>> Hi,
>>>
>>> for what it's worth, I am using a slightly hacked version of
>>> DB::CouchDB::Schema
>>>
>>> I actually don't use it much the way the author intended, and I have a
>>> lot of custom patches against it, but it does use user/pass type
>>> authentication for me.  I don't really want to get into maintaining a
>>> perl module, but in case you're interested I pushed my current working
>>> version to my github account.
>>>
>>> Feel free to email me with questions if you do use it.
>>>
>>> Regards,
>>> James
>>>
>>> On Mon, Apr 04, 2011 at 09:52:50AM -0600, Luis Miguel Silva wrote:
>>>> Thanks anyway!
>>>>
>>>> Has anybody on this list ever consumed the REST Api with
>>>> authentication (from a Perl Module)?
>>>> I'm guessing SOMEONE here will be running couchdb + a perl consumer in
>>>> a production environment ;o) hehehe
>>>>
>>>> Thanks!
>>>> Luis
>>>>
>>
>
>
>
> --
> twitter: @norbu09
> current project: iWantMyName.com
>

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by lenz <no...@googlemail.com>.
Hi,

I used all of the CouchDB modules available on CPAN and ended up
writing my own (Store::CouchDB) which is really extremely low level
and basic. i run it in production but via SSH tunnels so never
bothered with authentication. If i find a bit of time i can try to
hack it in but not sure if my modules are of any use to anyone other
than me in the moment as the interface is somehow inconsistent and
would need a major overhaul anyway.

how much interest is in the perl community for a complete
implementation rather than a "works for me" one?

cheers
lenz

On Thu, Apr 7, 2011 at 7:42 AM, Luis Miguel Silva
<lu...@gmail.com> wrote:
> That's great to know (and ill be sure to ask you if we continue working with CouchDB). So i really appreciate your offer.
>
> Unfortunatelly, my company decided to put CouchDB research on hold for now so we can evaluate other alternatives.
>
> Thank you!
> Luis Miguel Silva
>
> On Apr 6, 2011, at 1:30 PM, James Marca <jm...@translab.its.uci.edu> wrote:
>
>> Hi,
>>
>> for what it's worth, I am using a slightly hacked version of
>> DB::CouchDB::Schema
>>
>> I actually don't use it much the way the author intended, and I have a
>> lot of custom patches against it, but it does use user/pass type
>> authentication for me.  I don't really want to get into maintaining a
>> perl module, but in case you're interested I pushed my current working
>> version to my github account.
>>
>> Feel free to email me with questions if you do use it.
>>
>> Regards,
>> James
>>
>> On Mon, Apr 04, 2011 at 09:52:50AM -0600, Luis Miguel Silva wrote:
>>> Thanks anyway!
>>>
>>> Has anybody on this list ever consumed the REST Api with
>>> authentication (from a Perl Module)?
>>> I'm guessing SOMEONE here will be running couchdb + a perl consumer in
>>> a production environment ;o) hehehe
>>>
>>> Thanks!
>>> Luis
>>>
>



-- 
twitter: @norbu09
current project: iWantMyName.com

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Luis Miguel Silva <lu...@gmail.com>.
That's great to know (and ill be sure to ask you if we continue working with CouchDB). So i really appreciate your offer.

Unfortunatelly, my company decided to put CouchDB research on hold for now so we can evaluate other alternatives.

Thank you!
Luis Miguel Silva

On Apr 6, 2011, at 1:30 PM, James Marca <jm...@translab.its.uci.edu> wrote:

> Hi,
> 
> for what it's worth, I am using a slightly hacked version of
> DB::CouchDB::Schema
> 
> I actually don't use it much the way the author intended, and I have a
> lot of custom patches against it, but it does use user/pass type
> authentication for me.  I don't really want to get into maintaining a
> perl module, but in case you're interested I pushed my current working
> version to my github account.  
> 
> Feel free to email me with questions if you do use it.
> 
> Regards, 
> James
> 
> On Mon, Apr 04, 2011 at 09:52:50AM -0600, Luis Miguel Silva wrote:
>> Thanks anyway!
>> 
>> Has anybody on this list ever consumed the REST Api with
>> authentication (from a Perl Module)?
>> I'm guessing SOMEONE here will be running couchdb + a perl consumer in
>> a production environment ;o) hehehe
>> 
>> Thanks!
>> Luis
>> 

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by James Marca <jm...@translab.its.uci.edu>.
Hi,

for what it's worth, I am using a slightly hacked version of
DB::CouchDB::Schema

I actually don't use it much the way the author intended, and I have a
lot of custom patches against it, but it does use user/pass type
authentication for me.  I don't really want to get into maintaining a
perl module, but in case you're interested I pushed my current working
version to my github account.  

Feel free to email me with questions if you do use it.

Regards, 
James

On Mon, Apr 04, 2011 at 09:52:50AM -0600, Luis Miguel Silva wrote:
> Thanks anyway!
> 
> Has anybody on this list ever consumed the REST Api with
> authentication (from a Perl Module)?
> I'm guessing SOMEONE here will be running couchdb + a perl consumer in
> a production environment ;o) hehehe
> 
> Thanks!
> Luis
> 

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Luis Miguel Silva <lu...@gmail.com>.
Thanks anyway!

Has anybody on this list ever consumed the REST Api with
authentication (from a Perl Module)?
I'm guessing SOMEONE here will be running couchdb + a perl consumer in
a production environment ;o) hehehe

Thanks!
Luis

On Mon, Apr 4, 2011 at 1:39 AM, Paul Hirst <pa...@sophos.com> wrote:
> On Fri, 2011-04-01 at 19:08 +0100, Luis Miguel Silva wrote:
>> Dear Paul (and others),
> [snip]
>> 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 ??
>
> I'm afraid I'm not using authentication yet (bad bad me). I'm running in
> admin party mode. So I can't offer you any advice really. Sorry.
>
>
> Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
> Company Reg No 2096520. VAT Reg No GB 991 2418 08.
>

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Paul Hirst <pa...@sophos.com>.
On Fri, 2011-04-01 at 19:08 +0100, Luis Miguel Silva wrote:
> Dear Paul (and others),
[snip]
> 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 ??

I'm afraid I'm not using authentication yet (bad bad me). I'm running in
admin party mode. So I can't offer you any advice really. Sorry.


Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 991 2418 08.

Re: [somewhat off-topic] Any good perl modules for consuming CouchDB? Having trouble with Perl's CouchDB::Client

Posted by Luis Miguel Silva <lu...@gmail.com>.
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 <pa...@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.
>