leaving_traces leaving_traces - 4 months ago 19
Python Question

Flask to return nothing but only run script

To send email every day at 19:00 using Flask framework in Google app engine.

My program works just perfect, but my app intentionally generate

View function did not return a response


this error.

Here is my code below.

In


app.yaml


- url: /sendemail
script: send_email.app
login: admin


In


cron.yaml


cron:
- description: Send Email
url: /sendemail
schedule: every day 19:00


In


send_email.py


@app.route('/sendemail', methods=('GET', 'POST'))
def sendemail():
toaddr = "email@email.com"
body = "MYBODY"
to_email = mail.Email(toaddr)
from_email = mail.Email(SENDGRID_SENDER)
content = mail.Content('text/html', body)
subject = "SUBJECT"
message = mail.Mail(from_email, subject, to_email, content)


as you can see above in send_email.py, It doesn't return anything so my application return an error, but sending an email works just perfect.

So How can I achieve sending email without giving an error?

I am pretty new to Flask and web programming so I want to achieve this goal with only Flask (not Webapp2).

Thanks in advance.

Answer

Add this as a return statement for your sendemail function

return ('', 204)