これは私の最初の投稿です。私はtwilioを介してSMSの本文を取得しようとしています。最終的な目標は、テキストを使って基本的なチャットボットを作成することですが、1つのPythonファイル内のすべてをコーディングする必要はありません。それはそれを引き出すための目的だ。Twilio SMS/Pythonの本体をキャプチャしようとしています
私は、次にどこに向かうべきかに関するいくつかのガイダンスを探しています。それは私が身体を引き出したいのです方法に問題がある縫い目のよう
Traceback (most recent call last):
File "main.py", line 24, in <module>
print (sms_reply().message_body)
File "/home/pi/PythonScripts/BasicSMSBot/SMSIncoming.py", line 18, in
sms_reply
message_body = request.form['Body']
File "/usr/local/lib/python3.4/dist-packages/werkzeug/local.py", line 347,
in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/local/lib/python3.4/dist-packages/werkzeug/local.py", line 306,
in _get_current_object
return self.__local()
File "/usr/local/lib/python3.4/dist-packages/flask/globals.py", line 37, in
_lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
:ここで起動するには、 エラー(S)です。ここで
は現在SMSIncomingのコードです:ここで
#importing nessisary scripts and files
import os
#import SMSOutgoing
from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse
#initilizing the global user variable
#glo_user_var = (' T ');
#initilizing app
app = Flask(__name__)
@app.route("/sms", methods=["GET", "POST"])
def sms_reply():
resp = MessagingResponse()
#body = request.values.get('Body', None)
message_body = request.form['Body']
#for debuging the SMS instercept
#saveFile = open('bodyfile.txt', 'w')
#saveFile.write(body)
#saveFile.close()
resp.message("Testting the SMS responce")
return str(resp)
return str(body)
#lets main app process run
if __name__ == "__main__":
app.run(debug=True)
現在main.pyでmain.pyで
#place all imports and scripts to be run
import os
import SMSOutgoing
from SMSIncoming import sms_reply
#from SMSIncoming.py import app, sms_reply
import time
#call up ngrok and make server on port 5000
#os.system("./ngrok http 5000");
#start running the SMSIncoming app
#if __name__ == "__main__":
# app.run(debug=True)
# have to start apps separately! #
#this block will handle incoming SMS (User Input)
while True:
# global glo_user_var
print (sms_reply().message_body)
#file = open('test_user_input.txt', 'w')
#file.write(glo_user_var)
#file.close()
time.sleep(1)
すべてはテストのためにコメントアウトまたは代わりにされるかのコードです。
私がボディをプリントしたいのは、それが私がしたいところに行っていることを確認することです。その後、私はそれを返信を定義するユーザー入力として使用します。
また、httpウェブフックにngrokを使用しています。