Access-Control-Allow-Origin不允许使用Google App Engine发送邮件

时间:2013-09-20 04:58:24

标签: python google-app-engine email

我在使用Python通过Google App Engine发送电子邮件时遇到问题。我有一个在不同主机上运行的网站,其中包含在GAE中发布到Python脚本的表单。该脚本工作正常,但如果我在Python脚本中添加“发送邮件”功能,则会失败。我添加了:

    self.response.headers['Access-Control-Allow-Origin']='*'

但我仍然得到错误:

XMLHttpRequest cannot load http://www.summit-tech-help.appspot.com/. Origin http://summittechhelp.x10.mx is not allowed by Access-Control-Allow-Origin. 

这是我的Python脚本。

import cgi,webapp2
from google.appengine.api import mail

class ProblemRedirect(webapp2.RequestHandler):

    def post(self):
        self.response.headers['Access-Control-Allow-Origin']='*'
        problem_text = (cgi.escape(self.request.get('problem_text')))
        student_name =(cgi.escape(self.request.get('student_name')))
        student_email =(cgi.escape(self.request.get('student_email')))
        sender_address= "Summit Tech Help <techhelpsummit@gmail.com>"
        subject = "New Support Ticket!"
        body= "test."
        mail.send_mail(sender_address,sender_address,subject,body)




application = webapp2.WSGIApplication([
    ('/', ProblemRedirect),
], debug=True)

注释行是导致错误的原因。任何帮助,将不胜感激!谢谢!

〜Carpetfizz

我也尝试添加:

http_headers:
    Access-Control-Allow-Origin: "*"

到我的app.yaml文件,但我一直收到错误:

Error parsing yaml file:
Unexpected attribute "http_headers" for mapping type script.
  in "/Users/ajay/summit-tech-help/app.yaml", line 13, column 1

1 个答案:

答案 0 :(得分:0)

尝试添加以下行:

self.response.headers['Access-Control-Allow-Methods'] = 'POST'

直接在代码中,而不是在app.yaml。