Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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 在SELECT语句中使用请求体_Python_Sqlite_Flask_Twilio - Fatal编程技术网

Python 在SELECT语句中使用请求体

Python 在SELECT语句中使用请求体,python,sqlite,flask,twilio,Python,Sqlite,Flask,Twilio,我正在寻找一种方法来使用request.values.get from我的Twilio编号的主体,以便在SQLite中的SELECT语句中使用 基本上,如果我的Twilio号码的短信正文是ABC123,我想在select语句中使用该文本。。。Rego='ABC123'。显然,ABC123是动态的,将根据用户输入随时改变。。希望这有意义,我对SQLite和Python都是新手。提前谢谢 这是我的密码 from flask import Flask, request, redirect from t

我正在寻找一种方法来使用request.values.get from我的Twilio编号的主体,以便在SQLite中的SELECT语句中使用

基本上,如果我的Twilio号码的短信正文是ABC123,我想在select语句中使用该文本。。。Rego='ABC123'。显然,ABC123是动态的,将根据用户输入随时改变。。希望这有意义,我对SQLite和Python都是新手。提前谢谢 这是我的密码

from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)

@app.route("/sms", methods=['GET', 'POST'])
def incoming_sms():

    # Get the message body sent to my Twilio number
    body = request.values.get('Body', None)

#Below carries out the DB lookup based on body sent to my Twilio number
import sqlite3 


conn = sqlite3.connect('VinLookup.db')
c = conn.cursor()


def read_from_db():
    c.execute("SELECT Vin FROM Vin_Data WHERE Rego='ABC123'")
    data = c.fetchall()
    print(data)


read_from_db()   
c.close()
conn.close()

也许是这样的。所有数据库内容现在都在read_from_db函数中,该函数接受rego参数作为输入

import sqlite3
from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse


def read_from_db(rego):
    with sqlite3.connect("VinLookup.db") as conn:
        c = conn.cursor()
        c.execute("SELECT Vin FROM Vin_Data WHERE Rego=?", (rego,))
        return c.fetchall()


app = Flask(__name__)


@app.route("/sms", methods=["GET", "POST"])
def incoming_sms():
    body = request.values.get("Body", "")
    result = read_from_db(body)
    print(body, result)
    # Presumably return something here? A response to the SMS?

非常感谢你的帮助。。因此,为了响应SMS,我会使用body=request.values.POSTBody,