keyerror が出てうまくDBと接続できていないのか、コードが間違っているのでしょうか?
error
1--------------------------------------------------------------------------- 2KeyError Traceback (most recent call last) 3/usr/lib/python3.6/configparser.py in _unify_values(self, section, vars) 4 1137 try: 5-> 1138 sectiondict = self._sections[section] 6 1139 except KeyError: 7 8KeyError: 'mongo' 9 10During handling of the above exception, another exception occurred: 11 12NoSectionError Traceback (most recent call last) 134 frames 14<ipython-input-31-1444d8703338> in <module>() 15 157 16 158 if __name__ == "__main__": 17--> 159 pd = load_politly_dic(SENTIDIC_COLLECTION_NAME) 18 160 print(pd.shape, pd.head(10)) 19 161 20 21<ipython-input-31-1444d8703338> in load_politly_dic(collection_name) 22 53 23 54 def load_politly_dic(collection_name): 24---> 55 db = get_db(POLITELY_DICT_DB) 25 56 cursor = db[collection_name].find() 26 57 df = pd.DataFrame.from_dict(list(cursor)).astype(object) 27 28<ipython-input-31-1444d8703338> in get_db(db_name) 29 47 config.read(app_home + '/myvenv/lib/config.ini') 30 48 client = MongoClient('localhost') 31---> 49 client['admin'].authenticate(config.get('mongo', 'id'), config.get('mongo', 'password')) 32 50 # client = get_MongoClient() 33 51 db = client[db_name] 34 35/usr/lib/python3.6/configparser.py in get(self, section, option, raw, vars, fallback) 36 779 """ 37 780 try: 38--> 781 d = self._unify_values(section, vars) 39 782 except NoSectionError: 40 783 if fallback is _UNSET: 41 42/usr/lib/python3.6/configparser.py in _unify_values(self, section, vars) 43 1139 except KeyError: 44 1140 if section != self.default_section: 45-> 1141 raise NoSectionError(section) 46 1142 # Update with the entry specific variables 47 1143 vardict = {} 48 49NoSectionError: No section: 'mongo'
あなたの回答
tips
プレビュー