Data Sync problem - got 401 login required error

Hi all, I got the below error message when data sync is performed. My code is shown as below:

Error message in sync gateway:

POST /db/changes
—> 401 Login required <1.0 ms>

public void startSync() {

    URL syncUrl;
    try {
        syncUrl = new URL(SYNC_URL);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);

    Replication pullReplication = database.createPullReplication(syncUrl);

    Replication pushReplication = database.createPushReplication(syncUrl);

    Authenticator auth = AuthenticatorFactory.createBasicAuthenticator("adminaccount", "password");


What’s wrong of my code? Many thanks for help.

Did you create the user (adminaccount, password) through the Sync Gateway Admin REST API?

curl -vX POST http://localhost:4985/todos/_user/
       -H 'Content-Type: application/json'
       -d '{"name": "adminaccount", "password": "password"}'


I got the similar problem for my data sync if using admin account login on sync Gateway with 1.1.0 version.

Error Log
10:48:22,079 SEVERE [com.couchbase.lite] (CBLRequestWorker-38c6f-0) Sync: exception: %s
java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
at org.apache.http.impl.auth.BasicScheme.authenticate(
at org.apache.http.impl.auth.BasicScheme.authenticate(
at org.apache.http.client.protocol.RequestTargetAuthentication.process(
at org.apache.http.protocol.BasicHttpProcessor.process(
at org.apache.http.protocol.HttpRequestExecutor.preProcess(
at org.apache.http.impl.client.DefaultRequestDirector.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(
at java.util.concurrent.Executors$ Source)
at Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64 from [Module “deployment.Web.war:main” from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(
at org.jboss.modules.ConcurrentClassLoader.loadClass(

Below is my testing code

        Manager m = new Manager(new JavaContext(), Manager.DEFAULT_OPTIONS);
        Database db = m.getDatabase("test");
        URL url = new URL("");
        Replication pull = db.createPullReplication(url);
        Authenticator auth = AuthenticatorFactory.createBasicAuthenticator("admin","123"); 

Please help, thanks.

Does the user with name admin and password 123 exist in Sync Gateway?
See this tutorial for more info on creating users through the admin rest api.


I 've inputted the following in the browser

And it return the following info.


What are you trying to do?

4985 is the admin port so authentication will always be successful if the user exists in Sync Gateway.

Continuing the discussion from Data Sync problem - got 401 login required error:

Is it not your expected result? this is not correct way to check the user exists or not? please advice the method for checking…

Yes you can use this endpoint to check if the user exists.
But I’m not sure what isn’t working?
Are you still getting the 401 Unauthorised error when replicating with the Android SDK?

Hi @saitat,

From the stacktrace you provided, ClassLoader could not load the org.apache.commons.codec.binary.Base64.
I assume this could be caused by org.jboss.modules.ConcurrentClassLoader that I am not familiar with.

Is it possible to avoid to use org.jboss.modules.ConcurrentClassLoader on your app?
Or you can add as a dependency?

Hope this information helps you.