Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access CouchDB instance: returns 401 Unauthorized

Tags:

curl

couchdb

I can't access my couchdb instance it using curl or any third party CouchDB client library..

It returns: 401 Unauthorized!

I am using the url

https://instance.smileupps.com/

Using curl this is the command line I entered:

curl https://instance.smileupps.com/

like image 314
giowild Avatar asked Dec 02 '14 10:12

giowild


1 Answers

"401 Unauthorized" means that your instance is not in admin party (you have already specified at least one administrator credentials pair).

In this case you should send an authenticated request, both with curl or with any third party client side library.

1) THE EASY WAY (doesn't work with credentials with special characters)

You can use a modified url by prefixing the hostname with username:password like:

https://my_username:[email protected]

This works fine almost always..

2) THE TRICKY BUT SAFER WAY (More reliable and safer)

If 1) does not work, probably you are using special characters within your username or password, and curl or the couchdb library cannot correctly parse the url before sending the request.

In this case you can perform authentication by sending the http basic authorization header... that is a header like:

Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=

where "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=" is the base64_encode of "my_username:my_password". You can use the base64 online encoder service to encode your own credentials.

So the curl command line would become something like:

> curl -v -H "Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=" -H
> "Content-type:application/json" -X GET
> https://instance.smileupps.com/mydatabasename

If you are using a third party library instead, you should find in its documentation the way to add a custom header, and add the following:

Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=

like image 86
giowild Avatar answered Sep 20 '22 13:09

giowild