我想在Python中使用MongoDB,但每次我尝试访问/连接数据库或执行某些操作时,它都不起作用,并且在终端中显示错误。
代码如下:
import pymongo
myclient = pymongo.MongoClient('mongodb+srv://******:<**************>@cluster0.dr6egzq.mongodb.net/')
mydb = myclient['mydatabase']
mycol = mydb["customers"]
mydict = { "name": "John", "address": "Highway 37" }
x = mycol.insert_one(mydict)
print(x)
我得到的错误是:
Traceback (most recent call last):
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\testingMongo.py", line 11, in <module>
x = mycol.insert_one(mydict)
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\collection.py", line 628, in insert_one
self._insert_one(
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\collection.py", line 569, in _insert_one
self.__database.client._retryable_write(acknowledged, _insert_command, session)
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\mongo_client.py", line 1475, in _retryable_write
with self._tmp_session(session) as s:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\mongo_client.py", line 1757, in _tmp_session
s = self._ensure_session(session)
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\mongo_client.py", line 1740, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\mongo_client.py", line 1685, in __start_session
self._topology._check_implicit_session_support()
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\topology.py", line 538, in _check_implicit_session_support
self._check_session_support()
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\topology.py", line 554, in _check_session_support
self._select_servers_loop(
File "C:\Users\black\project\pythonproject\venv\Lib\site-packages\pymongo\topology.py", line 238, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError:
ac-yeuyapn-shard-00-01.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007),
ac-yeuyapn-shard-00-02.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007),
ac-yeuyapn-shard-00-00.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007),
Timeout: 30s,
Topology Description: <TopologyDescription id: 6467ddd302fb8613579250bb,
topology_type: ReplicaSetNoPrimary,
servers: [
<ServerDescription ('ac-yeuyapn-shard-00-00.dr6egzq.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yeuyapn-shard-00-00.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)')>,
<ServerDescription ('ac-yeuyapn-shard-00-01.dr6egzq.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yeuyapn-shard-00-01.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)')>,
<ServerDescription ('ac-yeuyapn-shard-00-02.dr6egzq.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-yeuyapn-shard-00-02.dr6egzq.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)')>
]>
2条答案
按热度按时间d8tt03nd1#
Try certifici包是一个Python库,它提供了一组根证书,用于验证SSL/TLS连接的真实性。
import certifi
g6baxovj2#
我认为它的工作,我需要ISRG根X1,ISRG根X2和让我们加密R3,并需要删除'< >'周围的连接字符串中的密码
https://letsencrypt.org/certificates/
这是第一个类别的.der下载
这在https://www.youtube.com/watch?v=dXvK-HZMG0A中有解释