Hello! I am not new to Python, but I am new to Pythonanywhere and somewhat new to programming with flask and dealing with servers/responses etc. I was gonna buy a cheap desktop and load Ubuntu server on it... maybe now I don't have to? :D BTW if someone solves this issue for me, I will become a paying member for sure :D as in tonight :D :D
I have developed a ton of apps for incoming and outgoing calls/texts/emails etc... such as the small example below. They all work on my local machine flawlessly, but the last few nights I have been unsuccessful at deploying them on pythonanywhere. I installed my virtualenv one directory above my "flaskapp" directory... not sure if that matters. I also activate it the way I learned in the past... source bin/activate... Would that cause and issue? It appears to activate just fine. I am using Python3.4 and pip3.4 (edit... redis with 3.5). Also noticed a post similar to this one mentioning Twilio Connect API. I can't seem to find it. It looked as some lines of code were added at the top.
As mentioned before I am new to this web stuff with Python. I usually use NGROK to expose my local address to the public internet. In Twilio, under my webhook where I usually post the the NGROK https url, I put http://myname.pythonanywhere.com/ I am assuming that's correct? All my apps rely heavily on Twilio API.
Any ideas?
from flask import Flask, request, redirect
from twilio.twiml.voice_response import VoiceResponse, Gather, Say
from twilio.rest import Client
import os
app = Flask(__name__)
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
@app.route("/", methods=['GET', 'POST'])
def hello():
resp = VoiceResponse()
resp.say("Hello. Leave a brief message. Speak slowly and clearly.")
resp.say("Then hang up when finished")
gather = Gather(input='speech',
timeout='10',
action="/handle-voice",
method="POST")
gather.say("You may start, now.")
resp.append(gather)
return str(resp)
@app.route("/handle-voice", methods=['GET', 'POST'])
def handle_voice():
resp = VoiceResponse()
transcription = request.values.get('SpeechResult', None)
from_number = request.values.get('From', None)
to_number = request.values.get('To', None)
confidence = request.values.get('Confidence', None)
first_message = "Thank you for calling. Your transcribed message is: \n"
first_message += "<" + transcription + ">"
first_message += "\nProjected confidence level:\n" + confidence + ".\n"
client.messages.create(to=from_number, from_=to_number, body=first_message)
second_message = "You're transcription in binary:\n"
for char in second_message:
second_message += bin(ord(char)) + '\n'
client.messages.create(to=from_number, from_=to_number, body=second_message)
return str(resp)
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)