私のコード:
import certifi
import ssl
from pymongo import MongoClient
connection = MongoClient("mongodb+srv://<USER>:<PASSWORD>@sensor-cluster-jhiup.mongodb.net/test", ssl_cert_reqs=ssl.CERT_REQUIRED, ssl_ca_certs=certifi.where())
print connection
db = connection.test
print db
items = db.items
print items
db.items.insert_one(
{"item": "canvas"})
Python 2.7 を介して mongodb atlas に単純な挿入を試みると、次のエラーが発生します。
MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017', 'sensor-cluster- shard-00-01-jhiup.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True, authsource=u'admin') データベース(MongoClient(host=['sensor-cluster) -shard-00-02-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-01-jhiup.mongodb .net:27017'], document_class=dict, tz_aware=False, connect=True, ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True, authsource=u'admin'), u'test') Collection(データベース(MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017', 'sensor-cluster -shard-00-01-jhiup.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True, authsource=u'admin'), u'test'), u'items ')テスト」) Collection(Database(MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017) ', 'sensor-cluster-shard-00-01-jhiup.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True, authsource=u'admin'), u'test '), u'アイテム')テスト」) Collection(Database(MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017', 'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017) ', 'sensor-cluster-shard-00-01-jhiup.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True, authsource=u'admin'), u'test '), u'アイテム')ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True、authsource=u'admin')、u'test')、u'items')ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem', replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True、authsource=u'admin')、u'test')、u'items')
トレースバック (最新の呼び出しが最後): ファイル "/Users/danielmatthews/Python/sunfounderpy3.py", line 18, in {"item": "canvas"}) ファイル "/Library/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/site-packages/pymongo/collection.py"、682 行目、insert_one session=session 内)、ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site -packages/pymongo/collection.py"、598 行目、_insert bypass_doc_val、session) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/collection.py" 、578 行目、_insert_one True、_insert_command、セッション内) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py"、1099 行目、in _retryable_write return self._retry_with_session(retryable, func, s, None) ファイル「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py」、1066行目、 _retry_with_session で self._get_socket(server) を sock_info として: ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py"、17 行目return self.gen.next () ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py"、944 行目、_get_socket と server.get_socket を入力します。 ( self.all_credentials) as sock_info: ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py"、17 行目、__enter return self.gen.next() File "/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/server.py"、138 行目、get_socket の self.pool.get_socket(all_credentials, checkout) を sock_info: File " /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py"、17 行目、Enter return self.gen.next() ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py"、893 行目、get_socket sock_info.check_auth(all_credentials ) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py"、588 行目、check_auth auth.authenticate(credentials, self) ファイル "/Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py"、486 行目、認証 auth_func(credentials, sock_info) ファイル内"/Library/Frameworks/Python.framework/ Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py"、466 行目、_authenticate_default return _authenticate_scram_sha1(credentials, sock_info) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py"、237 行目、_authenticate_scram_sha1 res = sock_info.command(source, cmd) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib /python2.7/site-packages/pymongo/pool.py"、496 行目、コマンド collation=collation 内) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ pymongo/network.py"、125 行目、コマンド parse_write_concern_error=parse_write_concern_error) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py"、146 行目, in _check_command_response raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth 認証に失敗しました。in _authenticate_scram_sha1 res = sock_info.command(source, cmd) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py"、496 行目、コマンド照合=collation) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/network.py"、125 行目、コマンド parse_write_concern_error=parse_write_concern_error) ファイル "/Library/Frameworks /Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py", line 146, in _check_command_response raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth Authentication failed.in _authenticate_scram_sha1 res = sock_info.command(source, cmd) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py"、496 行目、コマンド照合=collation) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/network.py"、125 行目、コマンド parse_write_concern_error=parse_write_concern_error) ファイル "/Library/Frameworks /Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py", line 146, in _check_command_response raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth Authentication failed.コマンドで collation=collation) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/network.py"、125 行目、コマンドで parse_write_concern_error=parse_write_concern_error) ファイル "/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py"、146 行目、_check_command_response で OperationFailure(msg % errmsg、code、response) を発生させる OperationFailure: 不正な認証認証失敗した。コマンドで collation=collation) ファイル "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/network.py"、125 行目、コマンドで parse_write_concern_error=parse_write_concern_error) ファイル "/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py"、146 行目、_check_command_response で OperationFailure(msg % errmsg、code、response) を発生させる OperationFailure: 不正な認証認証失敗した。146 行目 _check_command_response raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth 認証に失敗しました。146 行目 _check_command_response raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth 認証に失敗しました。