I am attempting to connect to MongoDB hosted on an AWS instance with a key file. I am able to ssh into the instance and connect to the database with no issues. When I try to connect to the database from a remote location with pymongo I receive this error:
ServerSelectionTimeoutError: SSL handshake failed: EOF occurred in violation of protocol
Port 27017 is open and the source is set to 0.0.0.0/0.
from pymongo import MongoClient
client = MongoClient('mongodb://ec2-123-45-678-910.compute-1.amazonaws.com',
27017,
ssl=True,
ssl_keyfile='/path_to/mykey.pem')
db = client.test
coll = db.foo
coll.insert_many(records)
ServerSelectionTimeoutError: SSL handshake failed: EOF occurred in violation of protocol (_ssl.c:645)
This question is nearly identical to mine, however the error is different and the solution posted there does not apply to my issue.
The address and key here have been changed, I have been going in circles on this for hours with no luck, any help would be appreciated.
This issue can cause because of following issue:
version of pymongo (suggest to use 3.3.0, which worked for me)
It can be a DNS issue, etc, in fact you could check for a DNS issue using:
telnet xx.xx.xx.xx port
can be a firewall issue
Can be an issue with ssl key. Try the following to test:
import os
import pymongo
import ssl
URL="url:port/db?ssl=true"
client = pymongo.MongoClient(URL, ssl_cert_reqs=ssl.CERT_NONE)
db = client.get_default_database()
print db
print db.collection_names()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With