nakagami / nmongo

Yet another MongoDB 3.x driver
MIT License
20 stars 0 forks source link

Connection with .der Certification OSError: [Errno 113] ECONNABORTED #5

Open rsemihkoca opened 1 year ago

rsemihkoca commented 1 year ago

Nakagami, hi,

yesterday I removed the issue because I tried incompletely, but today I made sure. I have a collection on Mongodb Atlas. After connecting with esp32, I will get data from a collection with filtering and I will not use other features.

However, during the connect phase OSError: [Errno 113] ECONNABORTED I get an error.

Pardon messiness

import socket
import ssl
import machine
from nmongo import MongoDatabase
import network
import gc
gc.enable()

ssid = "my_wifi_ssd"
password = "my_wifi_password"

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(ssid, password)

while not wifi.isconnected():
    pass

print("Connected to Wi-Fi")
print("IP address:", wifi.ifconfig()[0])

print("Allocated:", gc.mem_alloc(), "Free:", gc.mem_free())
database = "DB_NAME"
collection = "COLLECTION_NAME"

serverIP = "12.12.123.123"  # Sunucu IP adresini buraya girin
serverPort = 1234  # MongoDB'nin varsayılan bağlantı noktası

cert_file = "/cert/cloud-mongodb-com.der"

sock = socket.socket()
sock.connect(socket.getaddrinfo(serverIP, serverPort, socket.AF_INET)[0][-1])

#sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#sock.connect((serverIP, serverPort))
print("MongoDB'ye bağlandı!")

context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(cert_file)

ssl_sock = context.wrap_socket(sock, server_hostname=serverIP)

connectCommand = "use " + database + "\n"
ssl_sock.send(connectCommand.encode())

ssl_sock.close()

I used MongoDb atlas .pem file, converted it into .der file.

Model: ESP32 cp2102

nakagami commented 1 year ago

Sorry,this driver uses OP_COMMAND from MongoDB 3.x. https://www.mongodb.com/docs/v3.2/reference/mongodb-wire-protocol/

Because of OP_COMMAND has been removed since MongoDB 4.x, It will not connect to newer versions of MongoDB from Atlas.