【发布时间】:2021-11-23 16:28:15
【问题描述】:
我有一些代码可以直接连接到 Outlook 并从收件箱中提取元数据,然后编译成 pandas。但是,我似乎遇到了一个以前从未遇到过的错误,我怀疑它与 Outlook 提取中的错误数据(即电子邮件中的空白数据)有关。但我似乎无法隔离。有人见过这个吗?
ERROR:app:Exception on /ctplive [GET]
Traceback (most recent call last):
File "c:\programdata\anaconda\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "c:\programdata\anaconda\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "c:\programdata\anaconda\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "c:\programdata\anaconda\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "c:\programdata\anaconda\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "c:\programdata\anaconda\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "c:\programdata\anaconda\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\ADM\Code Projects\web_data_connector\outlook_api\app.py", line 100, in mailbox_insights
inbox['Conversation Length'] = determine_conversation_length(inbox['ConversationIndex'], archive['ConversationIndex']).astype(int).values
File "c:\users\adm\code projects\ccf_email_automation\ccf_email_automation\insights.py", line 92, in determine_conversation_length
res[index] = len([x[:len(index)] for x in list(inbox_index) + list(archive_index) if x[:len(index)] == index])
File "c:\users\adm\code projects\ccf_email_automation\ccf_email_automation\insights.py", line 92, in <listcomp>
res[index] = len([x[:len(index)] for x in list(inbox_index) + list(archive_index) if x[:len(index)] == index])
TypeError: 'NoneType' object is not subscriptable
这是来自 app.py 的块
if mailbox not in ['ctp', 'csu', 'dmt']:
return 404
archive, inbox = get_emails(mailbox, get_outlook())
inbox['Sender'] = inbox[['SenderName', 'SenderEmailAddress']].apply(lambda x: read_email_address(*x), axis=1)
inbox['Sender Domain'] = inbox['SenderEmailAddress'].apply(lambda x: x[x.index('@') + 1:] if '@' in x else 'gilead.com')
inbox['TABL_Highest Volume Senders'] = top_senders(inbox)
inbox['TABL_Highest Volume Sender Domains'] = top_sender_domains(inbox)
*************line 100 starts here**************
inbox['Conversation Length'] = determine_conversation_length(inbox['ConversationIndex'], archive['ConversationIndex']).astype(int).values
inbox['TABL_Longest Conversations'] = longest_conversations(inbox['Conversation Length'])
holiday_list = get_holidays()
inbox['Business Day SLA'] = inbox[['Received Date', 'Flag Completed Date']].apply(lambda x: calculate_sla(*x, holiday_list=holiday_list), axis=1)
inbox['Team Member'] = hardcode_team_member(inbox, mailbox)
inbox['Sentiment Score'] = determine_sentiment(inbox['Body'])
inbox['Flag Status'] = inbox[['Flag Completed Date', 'FlagRequest']].apply(lambda x: flag_status(*x), axis=1)
inbox['Complexity'] = inbox['Categories'].str.extract(r'Complexity Level (\d)').astype(float)
inbox['Protocol'] = inbox.pipe(identify_first_protocol)
inbox['Speed to Market'] = inbox['Categories'].str.contains('Speed to Market')
return inbox.rename(columns=lambda x: x.replace(' ', '_')).drop(columns=['ConversationIndex']).to_json(), 200
这是来自insights.py的块:
res = pd.Series(index=inbox_index, dtype='object')
for index in tqdm(inbox_index):
*******Line 92 starts here********
res[index] = len([x[:len(index)] for x in list(inbox_index) + list(archive_index) if x[:len(index)] == index])
return res
【问题讨论】:
-
你介意分享代码伙伴吗?
-
res或x不是列表(或其他可下标类型)。 -
@LibbyLebyane 对此感到抱歉,我已经添加了错误中引用的块。希望澄清,提前谢谢
-
您是否在调试器中单步执行代码以查看此时所有变量的值?你确定
pd.Series(index=inbox_index, dtype='object')正在返回一些东西吗?如果你还没有做基本的调试,请做。 PyCharm 是免费的,并且有一个很棒的调试器:jetbrains.com/help/pycharm/…
标签: python anaconda outlook-restapi