Can't access CouchDB instance: returns 401 Unauthorized Can't access CouchDB instance: returns 401 Unauthorized curl curl

Can't access CouchDB instance: returns 401 Unauthorized


"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:my_password@instance.smileupps.com

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=