Configuration Error : The DNS query name does not exist:_mongodb._tcp.nonr.mongodb.net
ConfigurationError at /testapi/
The DNS query name does not exist: _mongodb._tcp.none.mongodb.net.
utlis.py for extracting db list from mongo db This code works fine when run on a different python file, but I'm getting error when I run with a django project.
from urllib.parse import quote_plus
from pymongo import MongoClient
def auth(username, password, cluster_uri):
username = quote_plus(username)
password = quote_plus(password)
conn_str = "mongodb+srv://{}:{}@{}.mongodb.net/?retryWrites=true&w=majority".format(
username,
password,
cluster_uri
)
return MongoClient(conn_str)
def getDatabaseList(username, password, cluster_address):
client = auth(username, password, cluster_address)
dbs = client.list_database_names() # returns a list of databases
return dbs
views.py
from rest_framework import status
from rest_framework.decorators import permission_classes
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from .utils import getDatabaseList
u/permission_classes([AllowAny])
class TestViewSet(APIView):
def post(self, request):
username = request.data.get('username')
password = request.data.get('password')
cluster_address = request.data.get('cluster_address')
dblist = getDatabaseList(username, password, cluster_address)
return Response({'dblist': dblist}, status=status.HTTP_200_OK)
I got the solution Instead of using request.get.data('name') using request.POST['name'] worked flawle