Skip to main content
The First Step
March 8, 2021
Question

Message Store Export - name 'time' is not defined

I am using the python sample code from https://developers.ringcentral.com/guide/messaging/message-store/message-exports-report#python to try and export the message store. Using the exact same code, modified with my sandbox credentials and a later "dateTo", I get the following error. Any suggestions?

check task creation status ...
Traceback (most recent call last):
  File "sms.py", line 48, in <module>
    create_message_store_report()
  File "sms.py", line 15, in create_message_store_report
    get_message_store_report_task(json.id)
  File "sms.py", line 25, in get_message_store_report_task
    time.sleep(2)
NameError: name 'time' is not defined


    8 replies

    PhongVu
    Community Manager
    Community Manager
    March 8, 2021

    It is the Python standard lib. You just need to import the lib

    import time

    The First Step
    March 10, 2021

    Alright, I got that working. But now, the script just cycles through "check task creation status" until it exceeds the API limits. It doesn't actually do an export. And even though the analytics in my account shows over 1000 successful API calls, "status and review" shows "Your app hasn't made any API calls in Sandbox yet." All I'm trying to do here is export our SMS messages.

    PhongVu
    Community Manager
    Community Manager
    March 10, 2021

    In the example, to keep it short, I assumed that the task would be created successfully after some time. So I don't check for other statuses. You should check other statuses and decide when to stop the loop.

    Other task statuses: Accepted, Pending, InProgress, AttemptFailed, Failed, Completed, Cancelled

    def get_message_store_report_task(taskId):
        print("check task creation status ...")
        endpoint = "/restapi/v1.0/account/~/message-store-report/" + taskId
        response = platform.get(endpoint)
        json = response.json()
        if json.status == "Completed":
            get_message_store_report_archive(taskId)
        else:
            time.sleep(2)
            get_message_store_report_task(taskId)
    
    
    The First Step
    March 10, 2021

    The status is Failed. How do I find out why the status is Failed?

    The First Step
    March 11, 2021

    Ok, I figured out that the script was failing because my time range was too large. It seems to be successful now in generating an export, but when it goes to download it there is a 404 error. If I try and open the URL that is displayed by the script, I also get a 404 error. Any ideas?

    PhongVu
    Community Manager
    Community Manager
    March 11, 2021

    How did you download? Using exact code in the example? You cannot use the download url and open it from the browser unless you attach your access token to it.

    The First Step
    March 11, 2021

    Well the URL had a token in it. Regardless, the script itself is generating a 404 error.

    PhongVu
    Community Manager
    Community Manager
    March 11, 2021

    And this happens on your production account?