0

I have tried most of the solutions here but couldn't figure out why my call isn't reaching the other side. Though Twilio says that both incoming and outgoing was successfully completed.

Here's the necessary part of my code

from flask import Flask
from flask import request, Response

@app.route('/makeACall', methods=['POST'])
def exchange_voice():
  account_sid = "XXXX"
  auth_token = "XXXX"
  client = TwilioRestClient(account_sid, auth_token)
  call = client.calls.create(
    to="+1857XXX",
    from_="+1510XXX",
    url="cloudserver.com/answerWithXML",
    method='POST'
  )
  print(call.sid)

@app.route("/answerWithXML", methods=['GET', 'POST'])
def sendBackXML():
  resp = twilio.twiml.Response();
  resp.say("Welcome!");

//Was originally sending str(resp) as in docs

  return Response(resp, content_type="application/xml")

The debugger gives

  • "11200 - HTTP retrieval failure" for the returned response
  • "12100 - Document parse failure" when str(resp) was returned
Viginesh
  • 258
  • 1
  • 3
  • 16
  • What happens when you just make a GET request to your `answerWithXML` route in the browser? Are you importing the `twilio` library properly too (I only see imports for Flask)? – philnash Nov 21 '16 at 10:39
  • @philnash Yes, the twilio imports are properly added. I missed those here. When I was returning str(resp), the GET request displayed "Welcome!". The calls didn't get through even then. However, messaging works perfectly fine. – Viginesh Nov 21 '16 at 12:02
  • I'm wondering if we can make calls with trial accounts. Since I was trying out the API, I haven't upgraded to full account. – Viginesh Nov 21 '16 at 15:34
  • You can make calls with trial accounts, so that shouldn't be a problem. – philnash Nov 21 '16 at 15:52

1 Answers1

0

Twilio developer evangelist here.

I'm not entirely sure what's going on here. Your first version should have worked, that is, with the following code:

@app.route("/answerWithXML", methods=['GET', 'POST'])
def sendBackXML():
  resp = twilio.twiml.Response();
  resp.say("Welcome!");
  return str(resp);

Can you try that again and ensure that when you make a POST request to your local version of the code that you return the XML back that looks like:

<Response>
  <Say>Welcome!</Say>
</Response>

If you get that, then try again calling from Twilio. If not, then please update with the error that was reported and I'll try to help again.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • thanks for your answer. I tried printing the response in the sendBackXML() function. In my logs, I 1st got **'View function did not return a response'** and the call got cut with the message **'An App error occurred'**. 50s after the call got cut, the XML was printed exactly as above. Do I need to return any value in the 'exchange_voice' function? – Viginesh Nov 21 '16 at 23:38
  • I then tried using Twilio's voice.xml file. `call = client.calls.create(url="http://demo.twilio.com/docs/voice.xml", to="+185xx", from_="+151xx")` This too gave the same error. – Viginesh Nov 21 '16 at 23:41
  • Ok, weird, you seem to have a zero width whitespace character in the Twilio URL there. When I copy and paste it to a browser I got `https://demo.twilio.com/docs/voice.x%E2%80%8C%E2%80%8Bml`. So try with: https://demo.twilio.com/docs/voice.xml – philnash Nov 22 '16 at 00:21
  • As for your other errors, when you say you printed the response, do you mean with `print`? Because you need to `return` the response, as in my example. Have you tried that code as I've written it? You should return a value in your `exchange_voice` function, only so that the webserver can finish processing. It can just be a blank response. – philnash Nov 22 '16 at 00:22
  • I'm still returning `str(resp)`. Just added a `print` so that I can see if it's getting called and printing the right xml format. As for the 1st reply, yes the URL was wrong. I changed that and tried, it still gives me the "App error occurred. Goodbye" message on the call. – Viginesh Nov 22 '16 at 00:47
  • And then what does your Twilio log say for the call when you're using the demo url? – philnash Nov 22 '16 at 00:48
  • I feel like I should return XML Doc in `exchange_voice():`. I put a string "Call Success" in `exchange_voice()` and now the debugger error changed from "500 Internal Server Error" to "Twilio was unable to parse the provided XML Document. Your TwiML document must be a valid XML Document, or Twilio will not be able to read your document. You can debug XML parsing errors by getting the response body in the debugger, and then using an online validation tool like the W3C Validation Service." – Viginesh Nov 22 '16 at 00:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128662/discussion-between-philnash-and-the-man). – philnash Nov 22 '16 at 00:50