question

Moez Tharani avatar image
Moez Tharani asked Moez Tharani commented

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


sms and text messaging
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

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

import time

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Moez Tharani avatar image
Moez Tharani answered Phong Vu commented

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.

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

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)

0 Likes 0 ·
Moez Tharani avatar image
Moez Tharani answered

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

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Moez Tharani avatar image
Moez Tharani answered Phong Vu commented

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?

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

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.

0 Likes 0 ·
Moez Tharani avatar image
Moez Tharani answered Moez Tharani commented

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

4 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

And this happens on your production account?

0 Likes 0 ·
Moez Tharani avatar image Moez Tharani Phong Vu ♦♦ commented ·

No, I don’t have a production account yet. I’m still trying to generate enough API calls to apply.

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Moez Tharani commented ·

And you have SMS, voicemail or fax data on your sandbox?

0 Likes 0 ·
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys