OperationFailure: Authentication failed when backends/mongodb try write result

176 views
Skip to first unread message

Александр Замараев

unread,
Jan 16, 2020, 5:18:48 AM1/16/20
to celery-users
How do you fix this mistake?
CPython 3.8.1
celery 4.4.0
pymongo 3.10.1
stacktrace:

KeyError: 'collection'
 
File "kombu/utils/objects.py", line 42, in __get__
   
return obj.__dict__[self.__name__]
KeyError: 'database'
 
File "kombu/utils/objects.py", line 42, in __get__
   
return obj.__dict__[self.__name__]
OperationFailure: Authentication failed.
 
File "billiard/pool.py", line 1791, in safe_apply_callback
    fun
(*args, **kwargs)
 
File "celery/worker/request.py", line 526, in on_failure
   
self.task.backend.mark_as_failure(
 
File "celery/backends/base.py", line 159, in mark_as_failure
   
self.store_result(task_id, exc, state,
 
File "celery/backends/base.py", line 406, in store_result
   
self._store_result(task_id, result, state, traceback,
 
File "celery/backends/mongodb.py", line 194, in _store_result
   
self.collection.replace_one({'_id': task_id}, meta, upsert=True)
 
File "kombu/utils/objects.py", line 44, in __get__
    value
= obj.__dict__[self.__name__] = self.__get(obj)
 
File "celery/backends/mongodb.py", line 291, in collection
    collection
= self.database[self.taskmeta_collection]
 
File "kombu/utils/objects.py", line 44, in __get__
    value
= obj.__dict__[self.__name__] = self.__get(obj)
 
File "celery/backends/mongodb.py", line 286, in database
   
return self._get_database()
 
File "celery/backends/mongodb.py", line 275, in _get_database
   
if not db.authenticate(self.user, self.password, source=source):
 
File "pymongo/database.py", line 1468, in authenticate
   
self.client._cache_credentials(
 
File "pymongo/mongo_client.py", line 754, in _cache_credentials
   
with server.get_socket(all_credentials) as sock_info:
 
File "contextlib.py", line 113, in __enter__
   
return next(self.gen)
 
File "pymongo/pool.py", line 1138, in get_socket
    sock_info
.check_auth(all_credentials)
 
File "pymongo/pool.py", line 712, in check_auth
    auth
.authenticate(credentials, self)
 
File "pymongo/auth.py", line 564, in authenticate
    auth_func
(credentials, sock_info)
 
File "pymongo/auth.py", line 539, in _authenticate_default
   
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
 
File "pymongo/auth.py", line 263, in _authenticate_scram
    res
= sock_info.command(source, cmd)
 
File "pymongo/pool.py", line 603, in command
   
return command(self.sock, dbname, spec, slave_ok,
 
File "pymongo/network.py", line 165, in command
    helpers
._check_command_response(
 
File "pymongo/helpers.py", line 159, in _check_command_response
   
raise OperationFailure(msg % errmsg, code, response)


Oliver Saunders

unread,
Jan 16, 2020, 6:33:34 AM1/16/20
to celery...@googlegroups.com
Have you got code example? Check your backend connection string, looks like mongo db is failing authentication

--
You received this message because you are subscribed to the Google Groups "celery-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to celery-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/celery-users/af55c832-39ed-42c7-a64d-0c60414c62e4%40googlegroups.com.

Александр Замараев

unread,
Jan 16, 2020, 11:32:37 PM1/16/20
to celery-users
Code for initialization celery app:
from functools import partial
from bson import json_util

json_options=json_util.JSONOptions(
 
json_mode=json_util.JSONMode.RELAXED, tz_aware=True, tzinfo=utc)
json_dump = partial(
  json_util
.dumps, ensure_ascii=False, json_options=json_options)
json_load = partial(json_util.loads, json_options=json_options)

register(
 
'mongo_json',
 
encoder=(lambda obj: json_dump(obj).encode('utf-8')),
 
decoder=json_load,
 
content_type='application/x-mongo-json')

app = Celery(
 
'remains_tasks',
 
broker='pyamqp://...',
  backend = 'mongodb://...',
 
include=[
   
# many modules
 
]
)
app.conf.update(
 
accept_content=[
   
'mongo_json', 'application/x-mongo-json', 'json', 'application/json'],
 
task_serializer='mongo_json',
 
result_serializer='mongo_json',
 
task_default_queue='remains_tasks',
 
worker_prefetch_multiplier=1,
 
worker_max_tasks_per_child=45,
 
worker_hijack_root_logger=False,

 
mongodb_backend_settings=dict(database='remains', compressors='snappy'),
)
Connection string look:
mongodb+srv://username:password@mongo_server_host/database?ssl=false
Connection string - correct. It use in tasks.


четверг, 16 января 2020 г., 18:33:34 UTC+7 пользователь Oliver Saunders написал:
Have you got code example? Check your backend connection string, looks like mongo db is failing authentication

To unsubscribe from this group and stop receiving emails from it, send an email to celery...@googlegroups.com.

Александр Замараев

unread,
Jan 20, 2020, 11:10:03 PM1/20/20
to celery-users

Александр Замараев

unread,
Mar 3, 2020, 2:18:53 AM3/3/20
to celery-users
Also celery 4.4.1

четверг, 16 января 2020 г., 17:18:48 UTC+7 пользователь Александр Замараев написал:

Александр Замараев

unread,
Mar 19, 2020, 3:24:44 AM3/19/20
to celery-users
Also for celery 4.4.2, kombu 4.6.8, pymongo 3.10.1

Александр Замараев

unread,
Jun 6, 2020, 2:44:25 AM6/6/20
to celery-users
Also for celery 4.4.4kombu 4.6.10pymongo 3.10.1

четверг, 19 марта 2020 г., 14:24:44 UTC+7 пользователь Александр Замараев написал:
Reply all
Reply to author
Forward
0 new messages