TypeError:'NoneType'对象没有属性'__getitem__'| total_number_messages + = result [“verify_counter”]

时间:2015-07-18 10:35:55

标签: python django

print("* Parsing users email in parallel..") 
pool = Pool(processes=NUM_PROCESSES)
for result in pool.imap_unordered(worker, usernames, chunksize = 2): 
    total_number_messages += result["verify_counter"] 
    total_number_messages_imported += result["num_imported"] 
    total_number_duplicates += result["duplicate_counter"] 
    address_book[result["current_user_email"]] = result["username"] 
    combined_msg_senders.append({
                                "counter": result["counter"],
                                "address": result["current_user_email"],
                                "username": result["username"]
                                })
pool.close()
pool.join()

请帮助我解决此错误,获取上述错误

Traceback (most recent call last):
  File "metadata.py", line 539, in <module>
    main()
  File "metadata.py", line 511, in main
    total_number_messages += result["verify_counter"]
TypeError: 'NoneType' object has no attribute '__getitem__'

您可以查看的代码 http://brage.bibsys.no/xmlui/handle/11250/198551

1 个答案:

答案 0 :(得分:2)

result设置为None,因此result[...]失败。

如果result返回None,则

worker()None。确保您的员工始终返回结果,或首先明确测试result is not None