我正在尝试连接到我刚刚设置的 MongoDB 集群。但是,我收到这些错误,但我无法找到解决方案。帮助将不胜感激!
Python3
Mongodb Altas 集群 - 连接:
atlasstring = urllib.parse.quote(
"mongodb://<<MYEMAIL>>:<<MYPASSWORD>>@test-shard-00-00-3sqgv.mongodb.net:27017,test-shard-00-01-3sqgv.mongodb.net:27017,test-shard-00-02-3sqgv.mongodb.net:27017/test?ssl=true&replicaSet=test-shard-0&authSource=admin&retryWrites=true")
代码:
从 pymongo 导入 MongoClient 从 atlasclusterpassword 导入 atlasstring
client = MongoClient(atlasstring)
db = client.azuresupport
print(client.mflix)
错误:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 357, in get_socket
sock_info, from_pool = self.sockets.pop(), True
KeyError: 'pop from an empty set'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/idna.py", line 167, in encode
raise UnicodeError("label too long")
UnicodeError: label too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/bethwalsh/Documents/classification-twitter-app/test/test-mongo.py", line 6, in <module>
client = MongoClient(atlasstring)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 374, in __init__
self._ensure_connected(True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 939, in _ensure_connected
self.__ensure_member()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 813, in __ensure_member
member, nodes = self.__find_node()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 873, in __find_node
member, nodes = self.__try_node(candidate)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 716, in __try_node
sock_info = connection_pool.get_socket()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 361, in get_socket
sock_info, from_pool = self.connect(), False
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 288, in connect
sock = self.create_connection()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 258, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)
[Finished in 0.141s]