2017-09-18 61 views
0

我正在使用zeep連接到Five9呼叫中心API以檢索呼叫日誌報告。Python:Zeep錯誤

我的代碼如下:

class Five9api: 

    start = (datetime.now() - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) 
    end = datetime.now() 
    user = 'user' 
    pwd = 'pwd' 
    criteria = {'time': {'end': end, 'start': start}} 
    key = None 

    def __init__(self, folderName, reportName): 
     self.client = None 
     self.folderName = folderName 
     self.reportName = reportName 

    def open_client(self): 
     if self.client is None: 
      self.client = Five9(self.user, self.pwd) 

    def run_report(self): 
     identifier = self.client.configuration.runReport(folderName=self.folderName, reportName=self.reportName, 
                 criteria=self.criteria) 
     Five9api.key = identifier 

    def get_report_results(self): 
     get_results = self.client.configuration.getReportResult(Five9api.key) 

     return get_results 

我得到一個錯誤,當我使用的方法run_report返回傳遞到方法get_report_results的關鍵。什麼導致這個以下錯誤?

zeep.exceptions.Fault: Result is not ready due to process is not complete 

解決此錯誤的唯一方法是引入上述2種方法,像這樣之間的time.sleep ...

Report = Five9api("Call Log Reports", "Call Log") 
Report.open_client() 
Report.run_report() 
time.sleep(5) 
data = Report.get_report_results() 

回答

0

之前檢索與getReportResult報告結果,你可以檢查它是否願與isReportRunning方法:

def get_report_results(self): 
    while client.service.isReportRunning(identifier=Five9api.key, timeout=100): 
     None 
    get_results = self.client.configuration.getReportResult(Five9api.key) 

請參閱此處的完整文檔: Configuration Web Services, API Reference Guide