【问题标题】:exchangelib ews throttling policies pythonexchangelib ews节流策略python
【发布时间】:2022-11-17 01:43:21
【问题描述】:

我正在尝试建立一个包含所有电子邮件的数据库。

但我得到错误:

ErrorServerBusy:服务器现在无法为该请求提供服务。尝试 稍后再试。

有什么办法可以配合ews的节流策略吗?一个月的电子邮件确实有效,但当我超过一些未知的障碍时,它就会被打断。有没有其他方法可以防止节流策略?我考虑过实施 time.sleep(),但我怎么才能知道在收到多少封电子邮件后我需要等待多长时间才能使其正常工作?

shared_postboxes= [some accounts here]
credentials = Credentials(username=my username, password=my password)
config = Configuration(retry_policy=FaultTolerance(max_wait=600), credentials=credentials)

for shared_postbox in tqdm(shared_postboxes):

    account = Account(shared_postbox, credentials=credentials, autodiscover=True)
    top_folder = account.root
    email_folders = [f for f in top_folder.walk() if isinstance(f, Messages)]

    for folder in tqdm(email_folders):
    
        for m in folder.all().only('text_body', 'datetime_received',"sender").filter(datetime_received__range=(start_of_month,end_of_month), sender__exists=True).order_by('-datetime_received'):
        
            try: 
                senderdomain = ExtractingDomain(m.sender.email_address)
            
            except:
                print("could not extract domain")
        
            else:
                if senderdomain in domains_of_interest: 

                    postboxname = account.identity.primary_smtp_address
                    body = m.text_body
                    emails.append(body)
                    senders.append(senderdomain)
                    postbox.append(postboxname)
                    received.append(m.datetime_received)
    account.protocol.close()

【问题讨论】:

    标签: python outlook python-requests exchangewebservices exchangelib


    【解决方案1】:

    您创建了一个定义重试策略的 Configuration 对象,这是您想要解决问题的方法。但是您从未将配置传递给您的 Account 对象。为此,请将您的帐户创建为:

    account = Account(shared_postbox, config=config, autodiscover=True)
    

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      相关资源
      最近更新 更多