我使用MongoDB使用pymongo和下面的代码插入一些字段到我的文档
client = pymongo.MongoClient("mongodb://Mahdi-Bazargan-121:P_A_S_S_W_O_D@aws-ap-southeast-1-portal.2.dblayer.com:15312,aws-ap-southeast-1-portal.0.dblayer.com:15312/admin?ssl=true")
print("client is %s" %client)
mydb = client['BBCArticles']
print("db %s" % mydb)
my_collection = mydb['Articles']
print("my_collection %s" % my_collection)
myrecord = {"author": "Duke",
"title": "PyMongo 101",
"tags": ["MongoDB", "PyMongo", "Tutorial"],
"date": datetime.datetime.utcnow()
}
record_id = mydb.mytable.insert(myrecord)
print("record id %s" %record_id)
然而,我得到流动的错误
client is MongoClient(host=['aws-ap-southeast-1-portal.0.dblayer.com:15312', 'aws-ap-southeast-1-portal.2.dblayer.com:15312'], document_class=dict, tz_aware=False, connect=True, ssl=
True)
db Database(MongoClient(host=['aws-ap-southeast-1-portal.0.dblayer.com:15312', 'aws-ap-southeast-1-portal.2.dblayer.com:15312'], document_class=dict, tz_aware=False, connect=True, ss
l=True), u'BBCArticles')
my_collection Collection(Database(MongoClient(host=['aws-ap-southeast-1-portal.0.dblayer.com:15312', 'aws-ap-southeast-1-portal.2.dblayer.com:15312'], document_class=dict, tz_aware=F
alse, connect=True, ssl=True), u'BBCArticles'), u'Articles')
2017-02-16 01:40:05 [scrapy.core.scraper] ERROR: Spider error processing <GET http://www.bbc.com/> (referer: http://www.bbc.com/)
Traceback (most recent call last):
File "c:\python27\lib\site-packages\scrapy-1.3.1-py2.7.egg\scrapy\utils\defer.py", line 102, in iter_errback
yield next(it)
File "c:\python27\lib\site-packages\scrapy-1.3.1-py2.7.egg\scrapy\spidermiddlewares\offsite.py", line 29, in process_spider_output
for x in result:
File "c:\python27\lib\site-packages\scrapy-1.3.1-py2.7.egg\scrapy\spidermiddlewares\referer.py", line 22, in <genexpr>
return (_set_referer(r) for r in result or ())
File "c:\python27\lib\site-packages\scrapy-1.3.1-py2.7.egg\scrapy\spidermiddlewares\urllength.py", line 37, in <genexpr>
return (r for r in result or () if _filter(r))
File "c:\python27\lib\site-packages\scrapy-1.3.1-py2.7.egg\scrapy\spidermiddlewares\depth.py", line 58, in <genexpr>
return (r for r in result or () if _filter(r))
File "C:\Users\Mehdi\PycharmProjects\WebCrawler\src\Crawler.py", line 97, in parse
record_id = mydb.mytable.insert(myrecord)
File "c:\python27\lib\site-packages\pymongo\collection.py", line 2467, in insert
with self._socket_for_writes() as sock_info:
File "c:\python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "c:\python27\lib\site-packages\pymongo\mongo_client.py", line 823, in _get_socket
server = self._get_topology().select_server(selector)
File "c:\python27\lib\site-packages\pymongo\topology.py", line 214, in select_server
address))
File "c:\python27\lib\site-packages\pymongo\topology.py", line 189, in select_servers
self._error_message(selector))
ServerSelectionTimeoutError: SSL handshake failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661),SSL handshake failed: [SSL: CERTIFICATE_VERIFY_FAILED] cert
ificate verify failed (_ssl.c:661)
我写了正确的连接字符串,我也使用Python 2.7
1条答案
按热度按时间46qrfjad1#
用这条线代替