[Python] mongoDB 접속 에러 해결 - [SSL: CERTIFICATE_VERIFY_FAILED]

suno·2022년 10월 27일
1
post-thumbnail

mongoDB 인증 문제

python으로 mongoDB를 다루는 연습을 하고 있는데,

from pymongo import MongoClient
client = MongoClient("mongodb+srv://test:<password>@cluster0.9dl7gbc.mongodb.net/?retryWrites=true&w=majority")

위와 같이 작성하면 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 오류가 발생하며 mongoDB에 접근이 되지 않는다.

해결 방법

네트워크 환경에 따라 추가 보안이 필요하다는 것이었고, python 패키지 certifi를 통해 해결할 수 있다.

  1. python package - certifi 설치
  2. tlsCAFile=certifi.where() 추가
from pymongo import MongoClient
import certifi

client = MongoClient("mongodb+srv://test:<password>@cluster0.9dl7gbc.mongodb.net/?retryWrites=true&w=majority",
                     tlsCAFile=certifi.where())
db = client.test

doc = {
    'name': 'bob',
    'age': 27
}
db.users.insert_one(doc)

정상적으로 작동한다.

profile
Software Engineer 🍊

0개의 댓글

Powered by GraphCDN, the GraphQL CDN