Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法通过Gather方法中的action prop重定向到方法url_Python_Api_Oop_Twilio - Fatal编程技术网

Python 无法通过Gather方法中的action prop重定向到方法url

Python 无法通过Gather方法中的action prop重定向到方法url,python,api,oop,twilio,Python,Api,Oop,Twilio,我一直在尝试创建一个流程,以便在按键的基础上将修改后的输出发送回用户。 为此,我使用了twilio的Api 在继续我的问题之前,我将分享Route.py和CallResponse.py中的两段代码 app = Flask(__name__) logger = lh.log_initializer() @app.route("/Aresponse", methods=['GET', 'POST']) def ReceivedA(): """Respond to incoming requ

我一直在尝试创建一个流程,以便在按键的基础上将修改后的输出发送回用户。 为此,我使用了twilio的Api

在继续我的问题之前,我将分享Route.py和CallResponse.py中的两段代码

app = Flask(__name__)
logger = lh.log_initializer()

@app.route("/Aresponse", methods=['GET', 'POST'])
def ReceivedA():
    """Respond to incoming requests."""
    logger.debug("Starting ReceivedA flow| name:" + __name__)
    resp = tcr.RoutedReceivedA()
    return str(resp)

if __name__ == "__main__":
#    logger.debug("In routing main")
    app.run(debug=True, host='0.0.0.0', port=80, threaded=True)
下面是CallResponse.py的代码

app = Flask(__name__)
logger = lh.log_initializer()

def RoutedReceivedA():
    """Respond to incoming requests."""
    resp = VoiceResponse()
    resp.say("Hello Monkey")

    # Say a command, and listen for the caller to press a key. When they press
    # a key, redirect them to /user-input-key.
    logger.debug('Starting call receiving process|name:' + __name__)

    A_num = Gather(numDigits=2, action="/user-A-input", method="POST")

    A_num_entered = str(A_num)  #there is surely something not right with this line, but I am hardly bothered about this right now
    A_num.say("Please press a key to register your response")
    logger.debug("After taking A number from user| A num:" + A_num_entered)
    resp.append(A_num)

    return str(resp)

@app.route("/user-A-input", methods=['GET', 'POST'])
def UserAInput():
    """Handle key press from a user."""
    # Get the digit pressed by the user
    #The below logs are not printed, so somehow this method isn't called
    logger.debug('before considering user input in route')
    route_num = request.values.get('Digits', None)
    logger.debug('In side UserRouteInput| route_num:' + route_num)
    return route_num
因此,当我启动应用程序时,我点击url,请求首先在Route.py中接收到ReceivedA()方法,该方法在内部调用RoutedReceivedA(),该方法打印日志

正在启动呼叫接收进程|名称:

之后,我希望它重定向到方法UserAInput,因为我正在通过twilio库的Gather方法中的action属性传递方法URL,但它没有调用该方法。为了确认我也写了一个调试日志,它从不打印自己。 之后的痛苦是获取用户输入的值并将其传递给另一个方法(因为它将根据该输入进行api调用),而我现在并不担心这个问题

我试着理解烧瓶的工作原理,以验证我是否有什么地方做错了。我在这里遗漏了一些东西,但在不知不觉中我无法理解什么。 虽然我自己也在努力寻找解决办法,但我确实需要一些帮助


附言:我尝试使用twilio网站上的示例收集代码复制该问题,方法是创建maincall.py,它在内部调用twilio示例代码的hello_monkey()方法,然后调用handle key。即使在这种情况下,它也没有路由到handle_key()方法。但是,当我通过API调用直接调用hello_monkey()时,它工作正常。我相信我肯定是误解了一些关于烧瓶路由的概念。真的很沮丧

我找到了问题的解决办法。我需要

@app.route("/user-A-input", methods=['GET', 'POST'])
方法,而不是CallResponse.py
这可能是因为它正在使用在Route.py中创建的flask对象的实例。我仍然需要仔细研究,比如当你说你点击了,你是说在浏览器中吗?这意味着当我调用托管应用程序时,你是如何调用你的应用程序的?在Twilio的网站上有一个完整的逐步教程,我遵循了这个教程。
app = Flask(__name__)
logger = lh.log_initializer()

@app.route("/Aresponse", methods=['GET', 'POST'])
def ReceivedA():
    """Respond to incoming requests."""
    logger.debug("Starting ReceivedA flow| name:" + __name__)
    resp = tcr.RoutedReceivedA()
    return str(resp)

if __name__ == "__main__":
#    logger.debug("In routing main")
    app.run(debug=True, host='0.0.0.0', port=80, threaded=True)