Run Twilio CLI command using os.system results in error

367 Views Asked by At

I have a Twilio CLI command which I wish to run using Python os.system() on a Raspberry Pi, however it does not run properly... saying that it experiences an error.

I also do not understand the debug message...

The current code looks like this:

command_string = '/home/pi/.config/nvm/versions/node/v16.13.1/bin/twilio phone-numbers:update ' +my_number+ ' --sms-url=http://localhost:5000 -l debug'

os.system(command_string)

The Python script runs fine, but I keep getting the following results for the above command:

[DEBUG] Config File: /root/.twilio-cli/config.json
[DEBUG] Using profile: ${TWILIO_ACCOUNT_SID}/${TWILIO_AUTH_TOKEN}
[DEBUG] -- BEGIN Twilio API Request --
[DEBUG] GET https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/IncomingPhoneNumbers.json
[DEBUG] Querystring:
[DEBUG] {"PhoneNumber":"NUMBER"}
[DEBUG] Custom HTTP Headers:
[DEBUG] User-Agent: twilio-cli/2.35.0 @twilio/cli-core/5.32.2 (linux arm) twilio-node/3.71.3 node/v16.13.0 phone-numbers:update
[DEBUG] -- END Twilio API Request --
[DEBUG] response.statusCode: 200
[DEBUG] response.headers: {"date":"Sun, 12 Dec 2021 19:03:24 GMT","content-type":"application/json; charset=utf-8","content-length":"1585","connection":"close","twilio-concurrent-requests":"1","twilio-request-id":"RQ1c8c8551e33b2b8efaf2a3e93ce84050","twilio-request-duration":"1.085","access-control-allow-origin":"*","access-control-allow-headers":"Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since","access-control-allow-methods":"GET, POST, DELETE, OPTIONS","access-control-expose-headers":"ETag","access-control-allow-credentials":"true","x-powered-by":"AT-5000","x-shenanigans":"none","x-home-region":"us1","x-api-domain":"api.twilio.com","strict-transport-security":"max-age=31536000"}
[DEBUG] Found command "phone-numbers:update" plugin: twilio-cli
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg="no configuration paths supplied"
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg="ignoring default config path, could not stat it" path=/root/.ngrok2/ngrok.yml err="stat /root/.ngrok2/ngrok.yml: no such file or directory"
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg="starting web service" obj=web addr=127.0.0.1:4040
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg=start pg=/api/tunnels id=9ba04b3a3b59fd8f
t=2021-12-13T03:03:25+0800 lvl=warn msg="ngrok is not yet ready to start tunnels" pg=/api/tunnels id=9ba04b3a3b59fd8f err="a successful ngrok tunnel session has not yet been established"
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg=end pg=/api/tunnels id=9ba04b3a3b59fd8f status=503 dur=1.646498ms
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg=start pg=/api/tunnels id=38085fdc657c6c64
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=warn msg="ngrok is not yet ready to start tunnels" pg=/api/tunnels id=38085fdc657c6c64 err="a successful ngrok tunnel session has not yet been established"
t=2021-12-13T03:03:25+0800 lvl=info msg=end pg=/api/tunnels id=38085fdc657c6c64 status=503 dur=829.471µs
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg=start pg=/api/tunnels id=1d29d31d96b0c316
t=2021-12-13T03:03:25+0800 lvl=warn msg="ngrok is not yet ready to start tunnels" pg=/api/tunnels id=1d29d31d96b0c316 err="a successful ngrok tunnel session has not yet been established"
t=2021-12-13T03:03:25+0800 lvl=info msg=end pg=/api/tunnels id=1d29d31d96b0c316 status=503 dur=494.549µs
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=info msg=start pg=/api/tunnels id=541085ca341447c1
[DEBUG] ngrok: t=2021-12-13T03:03:25+0800 lvl=warn msg="ngrok is not yet ready to start tunnels" pg=/api/tunnels id=541085ca341447c1 err="a successful ngrok tunnel session has not yet been established"
t=2021-12-13T03:03:25+0800 lvl=info msg=end pg=/api/tunnels id=541085ca341447c1 status=503 dur=900.748µs
[DEBUG] ngrok: t=2021-12-13T03:03:26+0800 lvl=info msg=start pg=/api/tunnels id=894e9ee1a0583b59
[DEBUG] ngrok: t=2021-12-13T03:03:26+0800 lvl=info msg="tunnel session started" obj=tunnels.session
t=2021-12-13T03:03:26+0800 lvl=info msg="client session established" obj=csess id=fe7aff6afc5d
[DEBUG] ngrok: t=2021-12-13T03:03:26+0800 lvl=warn msg="failed to start tunnel" pg=/api/tunnels id=894e9ee1a0583b59 err="You must signup for ngrok and add your authtoken to perform this operation.\n\nSign up for an account: https://dashboard.ngrok.com/signup\nInstall your authoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
[DEBUG] ngrok: t=2021-12-13T03:03:26+0800 lvl=info msg=end pg=/api/tunnels id=894e9ee1a0583b59 status=502 dur=391.989355ms
[DEBUG] Found command "phone-numbers:update" plugin: twilio-cli
 » twilio-cli encountered an unexpected error. To report this issue, execute the command with the "-l debug" flag, then copy the output to a new issue here: "https://github.com/twilio/twilio-cli/issues"
[DEBUG] Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property '_httpMessage' -> object with constructor 'ClientRequest'
    --- property 'socket' closes the circle
[DEBUG] TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property '_httpMessage' -> object with constructor 'ClientRequest'
    --- property 'socket' closes the circle
    at JSON.stringify (<anonymous>)
    at NumberUpdate.createTunnel (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/src/commands/phone-numbers/update.js:94:51)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async NumberUpdate.run (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/src/commands/phone-numbers/update.js:48:9)
    at async NumberUpdate._run (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/node_modules/@oclif/command/lib/command.js:43:20)
    at async Config.runCommand (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/node_modules/@oclif/config/lib/config.js:173:24)
    at async Main.run (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/node_modules/@oclif/command/lib/main.js:27:9)
    at async Main._run (/home/pi/.config/nvm/versions/node/v16.13.1/lib/node_modules/twilio-cli/node_modules/@oclif/command/lib/command.js:43:20)

As a result, I cannot receive SMSs from Twilio...

Any idea on how to make this work?

2

There are 2 best solutions below

0
On

product manager for ngrok here. In an effort to curb abuse of the platform, we now require all users serving HTML content to have a free account. You will need to register for a free account at ngrok.com and add your authtoken to your ngrok config file or as a command line flag as described by Phil, even if you are using one of they ngrok libraries. If you have any questions or concerns, reach out to ngrok support! Thank you!

3
On

Twilio developer evangelist here.

There is an error from ngrok within the output here that says:

You must signup for ngrok and add your authtoken to perform this operation.

Sign up for an account: https://dashboard.ngrok.com/signup
Install your authoken: https://dashboard.ngrok.com/get-started/your-authtoken

ERR_NGROK_4018

So, it appears that you need to sign up for a free ngrok account and provide your authtoken.


It seems you are having some trouble orchestrating this application around Python and the Twilio CLI. You may find this easier to handle entirely in python. There is a Twilio Python library and an ngrok Python library that you could combine to start a tunnel and update a phone number's URL as part of your application.