Twilio REST API HTTP 400 error: “SendDigits must be less than 32 characters long”

会有一股神秘感。 提交于 2019-12-12 03:02:21

问题


One of my apps has been making Twilio REST API calls for more than a year without problems. For the last week, I consistently get this error now:

HTTP 400 error: {"message": "SendDigits must be less than 32 characters long", "status": 400}

My request looks like this (some information redacted): (method='POST', uri='https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxxx/Calls.json', **kwargs={'auth': ('xxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxx'), 'data': {'From': '+1415DDDDDDD', 'SendDigits': 'ww0w1234w16w6w415DDDDDDD#w415DDDDDDD#', 'To': '+1415DDDDDDD', 'Url': 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'}, 'headers': {'Accept': 'application/json', 'Accept-Charset': 'utf-8', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'twilio-python/3.6.13 (Python 2.7.6)'}})

It's as if the maximum length of SendDigits was recently changed, although I can't find documentation of this anywhere.

How can I get around this? Changing the value of the SendDigits isn't really an option for me.


回答1:


Megan from Twilio here.

Thank you for your feedback, I'm sorry for the trouble you are experiencing.

There is a workaround, to use <Play digits=""> in TwiML instead of passing it as a POST param, this should also be able to reach an equivalent result. For examples using <Play>, check out:

https://www.twilio.com/docs/api/twiml/play#attributes-digits

And an example in Python (using your string from above) would look something like:

def play_digits():
    r = twiml.Response()
    r.play(digits="ww0w1234w16w6w415DDDDDDD#w415DDDDDDD#")

    return str(r)

Please let me know if you find this to be useful.




回答2:


From Twilio's support staff:

"We rolled out a change a few days ago that restricted the max length of SendDigits to 32 characters. For a number of reasons we had to implement this limit."

Update: Solved. Here is my Python code:

call=client.calls.create(to=dial_number,from_="+14159999999",url="http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%20%20%20%20%3CPlay%20digits%3D%22"+urllib.quote_plus(send_digits)+"%22%3E%3C%2FPlay%3E%0A%3C%2FResponse%3E")

where send_digits is the string of digits you want to send (e.g. keypad entries). In this work-around, send_digits can be longer than 32 characters.



来源:https://stackoverflow.com/questions/36320949/twilio-rest-api-http-400-error-senddigits-must-be-less-than-32-characters-long

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!