配置错误:DNS查询名称不存在:_mongodb._tcp.nonr.mongodb.net

qyzbxkaa  于 2022-11-03  发布在  Go
关注(0)|答案(1)|浏览(184)
ConfigurationError at /testapi/
The DNS query name does not exist: _mongodb._tcp.none.mongodb.net.

输出出错:

utlis.py for extracting db list from mongo db这段代码在不同的python文件上运行时工作正常,但在运行django项目时出现错误。

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)
ttygqcqt

ttygqcqt1#

我得到了解决方案。而不是使用request.get.data('name')使用request.POST['name']工作完美

相关问题