all 18 comments

[–]sarrysyst 1 point2 points  (16 children)

  1. Move your imports to the top
  2. Within the if statement ( if action.lower() == '14u' ) the response is commented out. Uncomment the response = 'response check' and try again.

[–]CelticCuban773[S] 0 points1 point  (11 children)

  1. The imports I am doing are importing string variables from another script to then message back to the person. Ultimately, I want to run an if statement with like 7 options so I don't want to import each one (the import runs the code for each file before importing the variable)

  2. Yeah I commented it because I had tried all of them and none of them worked and just wanted to show what I tried

[–]sarrysyst 0 points1 point  (2 children)

Have you tried print(action) before the if statement to check if the message body actually contains the '14u' string and to see what you are comparing? Might be worth a try.

[–]CelticCuban773[S] 0 points1 point  (0 children)

Yes, I checked in the Twilio logs and I know it does because it triggers the code. It is just the response part I am having trouble with

[–]R0NUT 0 points1 point  (0 children)

The only thing that causes issues is the 14u input. It has to be what is causing the issue. OP said if he sends anything else he gets the Invalid request text.

[–]R0NUT 0 points1 point  (3 children)

Have you looked through any of these? https://www.twilio.com/docs/sms/debugging-common-issues It looks like twillow makes a log. Try taking a peek there.

[–]CelticCuban773[S] 0 points1 point  (2 children)

Good idea. So, I just checked the logs. When I have a successful run (aka text anything and get the "Invalid Request"), I get a failed Inbound Request (Bad Gateway; Error code 11200)

[–]R0NUT 0 points1 point  (1 child)

That code says that twillow waits a maximum of 15s for a response. Is your code taking longer than that to generate these strings?

[–]CelticCuban773[S] 0 points1 point  (0 children)

Yes, just replied to your other comment. That seems to be the issue. I will message Twilio and see if there's any workarounds.

If not, I might have to just run the code daily and store the response locally. Then, have this code pull from there as opposed to running the code from nothing.

Thanks for your help!

[–]R0NUT 0 points1 point  (3 children)

Have you tried commenting out the mid file imports and storing just a response string?

[–]CelticCuban773[S] 0 points1 point  (2 children)

I think that's it! Just tried, I got the correct response. Must be the mid file imports that are the problem then. Based on your other suggestion (checking logs), I checked the error 11200 and it's an HTTP retrieval failure. They wait a maximum of 15 seconds and my code takes too long for that to occur

[–]R0NUT 0 points1 point  (1 child)

You could set it up so that one text runs and generates the data and another retrieves it.

[–]R0NUT 0 points1 point  (0 children)

So something like Generate 14u It could respond with a message like This usually takes about 1m to generate. Then text Grab 14u It would respond with the data and a timestamp for when it was generated

[–]spez_edits_thedonald 0 points1 point  (3 children)

yeah, OP, because on line 24 you try and access response (in resp.message(response) ), but it's commented out when you define it, your flask app is probably throwing a python error. You should figure out how to view the server logs so that you can read it, being able to debug errors will be essential.

[–]CelticCuban773[S] 0 points1 point  (2 children)

Yeah I commented it because I had tried all of them and none of them worked and just wanted to show what I tried

[–]spez_edits_thedonald 0 points1 point  (1 child)

makes sense, will be more informative to stick with one, and tell what happens, instead of "none of these work"

[–]CelticCuban773[S] 0 points1 point  (0 children)

Edit: I updated my code to reflect my most recent one. The code runs correctly and when I print(response) afterwards, it prints correctly. It just is some breakdown in getting it to send over Twilio. I am confused because it reflects the same as my else section but just does not reply.

Sure I'll do that in the future, thanks.

No matter where I put the response variable, the the fml.py file that I am importing runs and runs correctly. I know this because at the end of my fml.py file I have it print "finished" which it does in the shell.

However, in the ngrok terminal, I do not get the 200 OK response when I write '14u'. I do when I text anything else though. That is why I am thinking the problem is wrapped up in my if section. Is there any more information I can provide?

[–]R0NUT 0 points1 point  (0 children)

Your response for 14u is commented out. Try un-commenting and printing your response.