I am trying to programmatically set up a cluster. For that I have followed the documentation (here https://docs.couchdb.org/en/stable/setup/cluster.html#the-cluster-setup-api), and created a quick python script that does it for me.
I then get the following output: {'error': 'setup_error', 'reason': 'Cluster setup unable to sync admin passwords'}. So I decided to try the Fauxton interface (which works) and see what goes over the line.
Made some changes to the python script to match exactly what Fauxton sends to the cluster... But were the manual interface (through Fauxton) works, I still get this "unable to sync" error when replicating what happens under the hood... This is driving me crazy now...
Using the following start script:
for i in {1..3}; \
do echo "$i"5984:5984; \
docker run -d --rm -p "$i"5984:5984 \
-e NODENAME=box0$i.couch -e ERL_FLAGS='-setcookie "brumbrum"' \
-e COUCHDB_USER=admin -e COUCHDB_PASSWORD=admin \
--name box0$i --network couch \
couchdb:3.1.1; \
done
which spins up three fresh docker containers using the 3.1.1 version of couchdb.
The script I use to clusterize you can find here: https://github.com/wasperen/couchdb_clusterify/blob/main/clusterize.py
Thanks for any help. But anyway: happy new year!
Just followed the documentation step by step, with the same result:
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "node_count":"3"}'
{"error":"bad_request","reason":"Cluster is already enabled"}
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "port": 5984, "node_count": "3", "remote_node": "box02.couch", "remote_current_user": "admin", "remote_current_password": "admin" }'
{"ok":true}
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "add_node", "host":"box02.couch", "port": 5984, "username": "admin", "password":"admin"}'
{"ok":true}
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "port": 5984, "node_count": "3", "remote_node": "box03.couch", "remote_current_user": "admin", "remote_current_password": "admin" }'
{"ok":true}
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "add_node", "host":"box03.couch", "port": 5984, "username": "admin", "password":"admin"}'
{"ok":true}
root#75c127f35ad6:~# curl -X POST -H "Content-Type: application/json" http://admin:admin#box01.couch:5984/_cluster_setup -d '{"action": "finish_cluster"}'
{"error":"setup_error","reason":"Cluster setup unable to sync admin passwords"}
And this from the browser logs, using the Fauxton user interface (on box01):
POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"singlenode":false}
RESPONSE 400 {"error":"bad_request","reason":"Cluster is already enabled"}
POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"remote_node":"box02.couch","remote_current_user":"admin","remote_current_password":"admin"}
RESPONSE 201 {"ok":true}
POST http://localhost:15984//_cluster_setup
DATA {"action":"add_node","username":"admin","password":"admin","host":"box02.couch","port":5984,"singlenode":false}
RESPONSE 201 {"ok":true}
POST http://localhost:15984//_cluster_setup
DATA {"action":"enable_cluster","username":"admin","password":"admin","bind_address":"0.0.0.0","port":5984,"node_count":3,"remote_node":"box03.couch","remote_current_user":"admin","remote_current_password":"admin"}
RESPONSE 201 {"ok":true}
POST http://localhost:15984//_cluster_setup
DATA {"action":"add_node","username":"admin","password":"admin","host":"box03.couch","port":5984,"singlenode":false}
RESPONSE 201 {"ok":true}
POST http://localhost:15984//_cluster_setup
DATA {"action":"finish_cluster"}
RESPONSE 201 {"ok":true}
GET http://localhost:15984/_membership
RESPONSE 200 {"all_nodes":["couchdb#box01.couch","couchdb#box02.couch","couchdb#box03.couch"],"cluster_nodes":["couchdb#box01.couch","couchdb#box02.couch","couchdb#box03.couch"]}
I think there might be a bug in CouchDB 3.x where it does not accept the finish_cluster action when basic authentication is being used. Seems like it works perfectly fine if you get a session cookie first through the _session endpoint and then use that for authentication.
I checked your code out, it looks all good seems like you are just hitting this issue here: https://github.com/apache/couchdb/issues/2858. It can get worked around with a GET request to the cluster coordinator node.
With the django rest framework I was using django-rest-framework-simplejwt from here.
According to the guideline given, my settings.py REST_FRAMERWORK should look like:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
),
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}
Now when I call the api /api/token/ with the help of CURL like this:
curl -X POST -H "Content-Type: application/json" -d '{"username": "aami", "password": "ooma"}' http://127.0.0.1:8000/api/token/
I get the following error:
curl -X POST -H "Content-Type: application/json" -d '{"username": "aami", "password": "ooma"}' http://127.0.0.1:8000/api/token/
And the server side the log is:
Bad Request: /api/token/
[12/Apr/2019 15:01:02] "POST /api/token/ HTTP/1.1" 400 75
I followed what the guidelines mentioned but I still can't figure out what's wrong.
This was happening to me. I realized I had created my users with
User.objects.create(username="xxx", password="yyy")
But in Django a special create_user method needs to be used. I deleted the user and changed to
User.objects.create_user(username="xxx", password="yyy")
and it worked.
I had a similar problem and turns out my problem was not activating the user after they have verified their emails using is_active=True. For more details check this out https://stackoverflow.com/a/70820311/12601926
I'm working with a third-party HTTP API like this:
curl https://secure.phabricator.com/api/maniphest.edit \
-d "api.token=${API_TOKEN}" \
-d "transactions[0][type]=subscribers.add" \
-d "transactions[0][value][0]=${OWN_USER_PHID}" \
-d "transactions[0][value][1]=${ANOTHER_USER_PHID}"
Basically it's a POST request with a request body like this (if written in Python syntax):
{"api.token": "...", "transactions": [{"type": "...", "value": ["...", "..."]}]
You can see that transactions is a nested array.
How do I encode such payload in Python? I'm using requests to make the request if that matters.
On ably.io they have an example where one can use the following curl request to publish a message to a channel:
curl -X POST https://rest.ably.io/channels/channelname/messages \
-u "some_AP.aYYMcQ:VmGHauKOqo-35Zxo" \
-H "Content-Type: application/json" \
--data '{ "name": "greeting", "data": "example" }'
The value passed to -u is an API key that has publish privileges. How does one make the same post request using Python requests library? I searched the documentation but could not find it. Note there is no password here, only the api key.
Thanks in advance.
You could use this:
requests.post("https://rest.ably.io/channels/channelname/messages",
auth=('some_AP.aYYMcQ', 'VmGHauKOqo-35Zxo'), # Equivalent of -u
json={ "name": "greeting", "data": "example" }) # Equivalent of --data
When you use the json option, -H is automatically set to Content-Type: application/json.
I was following the tastypie tutorial word for word until i reached the post part:
http://django-tastypie.readthedocs.org/en/latest/interacting.html#creating-a-new-resource-post
When i run this command i keep getting the following error:
No JSON object could be decoded
I checked and I am certain that I am following the documentation word for word.
Thanks for your help
Turned out to be a windows thing with cURL.
The JSON data should be quoted with double quotes ("") instead of single quotes.
All the double quotes in the json packet must be escaped with a backslash (\)
Eg: So, this:
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"body": "This will prbbly be my lst post.", "pub_date": "2011-05-22T00:46:38", "slug": "another-post", "title": "Another Post", "user": "/api/v1/user/1/"}' http://localhost:8000/api/v1/entry/
Should be:
curl --dump-header - -H "Content-Type: application/json" -X POST --data "{\"body\": \"This will prbbly be my lst post.\", \"pub_date\": \"2011-05-22T00:46:38\", \"slug\": \"another-post\", \"title\": \"Another Post\", \"user\": \"/api/v1/user/1/\"}" http://localhost:8000/api/v1/entry/