-1

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.

  • 1
    http://stackoverflow.com/a/24295616/6464893 Check out the answer I linked. Your function has to return something. – Harrison Aug 06 '16 at 12:44
  • @hleggs I tried that answer few days before but somehow this return ('', 204) didn't work for some reason. But now it's working great! Thank you – leaving_traces Aug 06 '16 at 12:59

1 Answers1

7

Add this as a return statement for your sendemail function

return ('', 204)
Harrison
  • 5,095
  • 7
  • 40
  • 60