程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何调用此函数来检查是否收到消息然后发送响应?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何调用此函数来检查是否收到消息然后发送响应??

开发过程中遇到如何调用此函数来检查是否收到消息然后发送响应?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何调用此函数来检查是否收到消息然后发送响应?的解决方法建议,希望对你解决如何调用此函数来检查是否收到消息然后发送响应?有所启发或帮助;

我有这个函数,它自己可以正常运行,但是当我尝试在另一个程序中调用它时它不起作用,我想用它来检查是否收到了消息,如果有则进行响应。

>

from flask import Flask,request
from twilio.twiml.messaging_response import MessagingResponse
from flask import Flask
app = Flask(__name__)

@app.route("/sms",methods =['POST'])
def sms_reply():
    number = request.form['From']
    m_b = request.form['Body']
    response_message='unkNown response,type KEW for a List of kNown words'
    resp = MessagingResponse()
    print(m_b)
    if m_b=='hello' or m_b== 'Hello':
        response_message='Hi,how are you?'
         
    elif m_b=='KEW' or m_b== 'kew' or m_b== 'Kew':
        response_message='hello,..... yeh thats only one i have set up so far im still testing it'

    resp.message(response_message)

    return str(resp)

if __name__ == "__main__":
    app.run(deBUG=True)

被调用的程序

def bot():
    
       
    timer=time.time()
    sold_out=True 
    
    print('Bot is starting')                                                                                                                                                                         
    print('Loading item page')
    still_running_check=0        
    while sold_out==True:                                                                                                                                       #while item is sold out reload the page and print sold out to the console
       driver.get(item_url)                      
       #time.sleep(1)
       sold_out=check_exists_by_xpath("/HTML/body/div[3]/main/div[2]/div[3]/div[2]/div/div/div[6]/div[1]/div/div/div/button")                                   
       still_running_check+=1
       sms_reply()
       #if still_running_check%100==0:
           #sms('Bot is still running and is on attempt '+str(still_running_check)+'\n '+str(round((time.time()-timer)/60,2))+' minute(s) have passed')
       if sold_out==False:
           break
       else:
           print ("Sold out")
    
    cart_button = driver.find_element_by_class_name("fulfillment-add-to-cart-button")                                                                   #once sold out is no longer true add to cart button is clicked
    cart_button.click()
    time.sleep(1)
    driver.get("https://www.bestbuy.com/checkout/r/fast-track")                                                                                             #navigates to checkout page
    time.sleep(1)
    code= driver.find_element_by_xpath('//*[@ID="credit-card-cvv"]')                                                                                        #csv input location
    code.send_keys(security_code)                                                                                                                           #inputs prevIoUsly given csv code
    time.sleep(2)
    #confirm_button= driver.find_element_by_class_name("button--place-order-fast-track")
    #confirm_button.click()
    
    print('Order submission screenshot saved as "OrderSubmission.png" in repository location')                                                              #order completion code
    driver.get_screenshot_as_file('OrderSubmission.png')
    sms('Bot Program executed succesfully for '+Title.text)
    end=input(Title.text+' program executed succesfuly hit enter to exit browser or type retry to start bot again:')                                                    #if program ran all the way through will print program ran succesfully
    if end=='retry':
                bot()

这将返回错误“在请求上下文之外工作。

这通常意味着您尝试使用需要的功能 一个活动的 http 请求。请参阅有关测试的文档 有关如何避免此问题的信息。”

我查看了烧瓶文档,看到了这个 “这通常只会在测试需要活动请求的代码时发生。一种选择是使用测试客户端来模拟完整请求。或者您可以在 with 块中使用 test_request_context(),并且在块中运行的所有内容都将具有访问请求,填充了您的测试数据。”

但我真的不明白它在说什么以及如何将其实现到我的代码中

解决方法

这里是 Twilio 开发者布道者。

您的第一个函数 sms_reply 看起来好像设置为 receive an incoming webhook from Twilio when an SMS message is sent to your Twilio phone number。该函数接收传入的 HTTP 请求,检查消息正文,构造回复并将其作为对请求的响应返回。

问题在于,您随后尝试在第二段代码中调用该函数,该函数期望响应 HTTP 请求,而该函数似乎根本没有与之相关的 HTTP 请求。

>

如果您想要 list messages that you have received 或 send a message,您可能会发现您想要使用 Twilio REST API。我不确定你的代码到底想做什么,所以我不能比这更具体。

大佬总结

以上是大佬教程为你收集整理的如何调用此函数来检查是否收到消息然后发送响应?全部内容,希望文章能够帮你解决如何调用此函数来检查是否收到消息然后发送响应?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: