1

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?

Russ Savage
  • 548
  • 2
  • 14
xyiong
  • 363
  • 1
  • 10

2 Answers2

1

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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Hi, I have an account and can do ```ngrok http 5000``` from my terminal, but am not able to run this command using os.system(). I am not sure what is the issue or can find any solution... – xyiong Dec 13 '21 at 05:27
  • ngrok usually keeps the auth token in a file at `~/.ngrok2/ngrok.yml`. In your case that looks like it should be `/root/.ngrok2/ngrok.yml`. I'm guessing that you have an `.ngrok2` directory in your own user directory, but not the `root` user directory, so see if you can copy it across. – philnash Dec 13 '21 at 05:30
  • thank you for your help! I got it to work, but the result was not what I was expecting. I therefore decided to use the ngrok Python library. However, that started giving me some problems. I pip uninstalled pyngrok and the problem persisted. I am unsure if the problem was pyngrok or my program. The problem has been posted here using a test program: https://stackoverflow.com/questions/70326878/run-twilio-cli-command-using-os-system-results-in-error. Any help would be much appreciated – xyiong Dec 13 '21 at 12:31
1

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!

Russ Savage
  • 548
  • 2
  • 14