Hi I have a django project which in local it works fine. I deploy on a remote server but mongodb it seems doesn’t work because I have this partial traceback:
djongo.exceptions.SQLDecodeError:
Keyword: FAILED SQL: SELECT "station"."station_name", "station"."id_station" FROM "station"
Params: ()
Pymongo error: OrderedDict([('ok', 0.0), ('errmsg', 'command find requires authentication'), ('code', 13), ('codeName', 'Unauthorized')])
Version: 1.3.6
Sub SQL: None
FAILED SQL: None
Params: None
Version: None
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/kafka/anaconda3/envs/djangocrops/lib/python3.9/site-packages/django/db/utils.py", line 97, in inner
return func(*args, **kwargs)
File "/home/kafka/anaconda3/envs/djangocrops/lib/python3.9/site-packages/djongo/cursor.py", line 70, in fetchmany
raise db_exe from e
djongo.database.DatabaseError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/kafka/anaconda3/envs/djangocrops/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/home/kafka/anaconda3/envs/djangocrops/lib/python3.9/threading.py", line 910, in run
I set my mongodb in settings and in a utils.py file:
DB django settings:
DATABASES = {
'default': {
'ENGINE' : 'djongo',
'NAME' : 'meteodata',
'HOST': '127.0.0.1', #localhost',
'PORT': 27017,
'USERNAME': 'admin',
'PASSWORD': 'mypwd',
'MONGO_URI': "mongodb://admin:mypwd@127.0.0.127017/meteodata"
}
}
utils.py
from pymongo import MongoClient
import pymongo
def get_db_handle(db_name, host, port, username, password): #, username, password):
client = MongoClient(host=host,
port=int(port),
username=username,
password=password,
authSource="admin",
)# localhost 27017
print('client', client)
db_handle = client[db_name]
return db_handle, client
def get_collection_handle(db_handle, collection_name):
return db_handle[collection_name]
client = get_db_handle('meteodata', '127.0.0.1', 27017, 'admin', 'mypwd')[1]
collection = client.meteodata
What went wrong?
Some hint?
Thx,