2

I'm trying to use MongoDB on Amazon EC2 using Python3.4.3.
I followed this answer: modified security groups setting and edited "/etc/mongod.conf" (comment out bind_id). However, when I run following code, I got this error:

ServerSelectionTimeoutError: SSL handshake failed: [Errno 54] Connection reset by peer

What else should I do?

The code I run is:

import pymongo
import ssl
client = pymongo.MongoClient('ec2-**-**-*-**.us-west-2.compute.amazonaws.com', 27017, 
ssl=True, ssl_keyfile='/Users/S/FILENAME.pem')

db = client["test"]
db.artist
collection = db.artist

import gzip
import json
from io import StringIO

with gzip.open('artist.json.gz', "rt") as a_file: 
    count=0
    bulk = []
    for line in a_file:
        jdata = json.load(StringIO(line)) 

        bulk.append(jdata) 
        count += 1

        if 1000 < count:
            print ('bulk insert!')

            collection.insert_many(bulk)
            bulk = []
            count = 0

    if len(bulk) > 0:
        collection.insert_many(bulk)
Community
  • 1
  • 1
user51966
  • 967
  • 3
  • 9
  • 21

0 Answers0