我从脚本中获取以下代码片段,该脚本从数组中获取zipcode,使用该zipcode获取url,并使用simplejson解析并将其加载到mongodb中。
zipcodes = ['10005']
for z in zipcodes:
r = requests.get('example.org/zipcode/not-the-real-url')
rj = simplejson.loads(r.content)
for doc in rj:
groupcoll.insert(doc)
grouplist.append(doc['urlname'])
在zipcodes数组中只有一个项目按预期工作,但是当我添加第二个项目时,即
zipcodes = ['10005', '20005']
不做其他改动,这是输出:
Traceback (most recent call last):
File "meetup_description_analyze.py", line 28, in <module>
groupcoll.insert(doc)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 2212, in insert
check_keys, manipulate, write_concern)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 583, in _insert
gen(), check_keys, self.__write_response_codec_options, bwc)
File "/usr/local/lib/python2.7/dist-packages/pymongo/message.py", line 770, in _do_batched_write_command
for doc in docs:
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 551, in gen
doc['_id'] = ObjectId()
TypeError: 'str' object does not support item assignment
我在俯瞰什么?我不是专家(obvs。)但我认为这很好,我的故障排除能力已经结束了。 TIA。