python(24) pymongo. errors(24).ServerSelectionTimeoutError 言語処理100本ノック:64 未解決

言語処理100本ノック 2015
# 64. 
MongoDBの構築
http://www.cl.ecei.tohoku.ac.jp/nlp100/
「アーティスト情報（artist.json.gz）をデータベースに登録せよ．さらに，次のフィールドでインデックスを作成せよ: name, aliases.name, tags.value, rating.value．」
素人の言語処理100本ノック:64
https://qiita.com/segavvy/items/8f93187ec89f4831d863

```
./p64.py
Traceback (most recent call last):
  File "./p64.py", line 28, in <module>
    collection.insert_many(buf)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/collection.py", line 753, in insert_many
    blk.execute(write_concern, session=session)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/bulk.py", line 521, in execute
    return self.execute_command(generator, write_concern, session)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/bulk.py", line 344, in execute_command
    with client._tmp_session(session) as s:
  File "/opt/conda/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session
    s = self._ensure_session(session)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
    server_session = self._get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
    return self._topology.get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
    None)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
```

ソースは下記（コマンドとして実行したく１行目追記）

```
#!/usr/bin/env python
# coding: utf-8

import gzip
import json
import pymongo
from pymongo import MongoClient

fname = 'artist.json.gz'
unit_bulk = 10000       # バルクインサートする単位（件）

# MongoDBのデータベースtestdbにコレクションartistを作成
client = MongoClient()
db = client.testdb
collection = db.artist

# gzファイル読み込み
with gzip.open(fname, 'rt') as data_file:

    # 1行ずつパースしてbufに詰め込む
    buf = []
    for i, line in enumerate(data_file, 1):
        data_json = json.loads(line)
        buf.append(data_json)

        # unit_bulk件たまったらartistへバルクインサート
        if i % unit_bulk == 0:
            collection.insert_many(buf)
            buf = []
            print('{}件追加完了'.format(i))

    # 最後のunit_bulkに入らなかった半端分の追加
    if len(buf) > 0:
        collection.insert_many(buf)
        print('{}件追加完了'.format(i))

# インデックス作成
collection.create_index([('name', pymongo.ASCENDING)])
collection.create_index([('aliases.name', pymongo.ASCENDING)])
collection.create_index([('tags.value', pymongo.ASCENDING)])
collection.create_index([('rating.value', pymongo.ASCENDING)])
```

# p65.py

```
# ./p65.py
Traceback (most recent call last):
  File "./p65.py", line 17, in <module>
    for i, doc in enumerate(collection.find({'name': 'Queen'}), start=1):
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1189, in next
    if len(self.__data) or self._refresh():
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1087, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
    server_session = self._get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
    return self._topology.get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
    None)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
```

#p67.py

```
# ./p67.py
アーティストの別名を入力して下さい--> beethoven
Traceback (most recent call last):
  File "./p67.py", line 19, in <module>
    for i, doc in enumerate(collection.find({'aliases.name': clue}), start=1):
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1189, in next
    if len(self.__data) or self._refresh():
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1087, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
    server_session = self._get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
    return self._topology.get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
    None)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
```

# p68.py

```
# ./p68.py
Traceback (most recent call last):
  File "./p68.py", line 16, in <module>
    for i, doc in enumerate(results[0:10], start=1):
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1189, in next
    if len(self.__data) or self._refresh():
  File "/opt/conda/lib/python3.7/site-packages/pymongo/cursor.py", line 1087, in _refresh
    self.__session = self.__collection.database.client._ensure_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
    server_session = self._get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
    return self._topology.get_server_session()
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
    None)
  File "/opt/conda/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
```

## 一覧
物理記事　上位100
https://qiita.com/kaizen_nagoya/items/66e90fe31fbe3facc6ff

量子(0) 計算機, 量子力学 
https://qiita.com/kaizen_nagoya/items/1cd954cb0eed92879fd4

数学関連記事１００
https://qiita.com/kaizen_nagoya/items/d8dadb49a6397e854c6d

言語・文学記事　１００
https://qiita.com/kaizen_nagoya/items/42d58d5ef7fb53c407d6

医工連携関連記事一覧
https://qiita.com/kaizen_nagoya/items/6ab51c12ba51bc260a82

自動車　記事　１００
https://qiita.com/kaizen_nagoya/items/f7f0b9ab36569ad409c5

通信記事１００
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7

日本語（０）一欄
https://qiita.com/kaizen_nagoya/items/7498dcfa3a9ba7fd1e68

英語(0) 一覧
https://qiita.com/kaizen_nagoya/items/680e3f5cbf9430486c7d

転職(0)一覧
https://qiita.com/kaizen_nagoya/items/f77520d378d33451d6fe

仮説（0）一覧（目標100現在40）
https://qiita.com/kaizen_nagoya/items/f000506fe1837b3590df

Qiita(0)Qiita関連記事一覧（自分）
https://qiita.com/kaizen_nagoya/items/58db5fbf036b28e9dfa6

鉄道（０）鉄道のシステム考察はてっちゃんがてつだってくれる
https://qiita.com/kaizen_nagoya/items/26bda595f341a27901a0

安全（0）安全工学シンポジウムに向けて: 21
https://qiita.com/kaizen_nagoya/items/c5d78f3def8195cb2409

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

Ethernet 記事一覧　Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48) 
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網（Wi-Fi）空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

OSEK OS設計の基礎　OSEK(100)
https://qiita.com/kaizen_nagoya/items/7528a22a14242d2d58a3

Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

++ Support(0)　
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding(0) Rules, C, Secure, MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

プログラマによる、プログラマのための、統計(0)と確率のプログラミングとその後
https://qiita.com/kaizen_nagoya/items/6e9897eb641268766909

なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2

言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4

プログラムちょい替え（0）一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394

官公庁・学校・公的団体（NPOを含む）システムの課題、官（０）
https://qiita.com/kaizen_nagoya/items/04ee6eaf7ec13d3af4c3

「はじめての」シリーズ　 ベクタージャパン　
https://qiita.com/kaizen_nagoya/items/2e41634f6e21a3cf74eb

AUTOSAR(0)Qiita記事一覧, OSEK(75)
https://qiita.com/kaizen_nagoya/items/89c07961b59a8754c869

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

LaTeX(0) 一覧　
https://qiita.com/kaizen_nagoya/items/e3f7dafacab58c499792

自動制御、制御工学一覧（０）
https://qiita.com/kaizen_nagoya/items/7767a4e19a6ae1479e6b

Rust(0) 一覧　
https://qiita.com/kaizen_nagoya/items/5e8bb080ba6ca0281927

小川清最終講義、最終講義（再）計画, Ethernet(100) 英語(100) 安全(100)
https://qiita.com/kaizen_nagoya/items/e2df642e3951e35e6a53


＜この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。＞
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.
### 文書履歴(document history)
ver. 0.01 初稿 　20240504
### 最後までおよみいただきありがとうございました。
いいね　💚、フォローをお願いします。
#### Thank you very much for reading to the last sentence.
Please press the like icon 💚　and follow me for your happy life.