Access-Control-Allow-Origin与Google App Engine应用程序不允许使用null

时间:2013-09-20 00:43:21

标签: python google-app-engine

我有一个在我自己的域上运行的网站,它有一个表单,其中有一个指向我的google appspot域的操作。 app spot app正在运行一个非常简单的python脚本,如下所示:

import cgi,webapp2


class ProblemRedirect(webapp2.RequestHandler):

    def post(self):
        print(cgi.escape(self.request.get('problem_text')))
        print(cgi.escape(self.request.get('student_name')))
        print(cgi.escape(self.request.get('student_email')))



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

以下是我的表单的HTML:

<div id="mainForm">
            <form id="problem_form" class="problem_form" action="http://www.summit-tech-help.appspot.com" method="post">
                <textarea id="problemText" placeholder="Explain your problem in detail. Click the black bar on top, for rules!" form="problem_form" rows="15" cols="45" name="problem_text" autofocus required></textarea></br>
                <input type="text" placeholder="Enter your email..." name="student_email" required/></br>
                <input type="text" placeholder="Your name..." name="student_name" required/></br>
                <input type="submit" value="Submit!" required/>
            </form>
        </div>

此表单位于另一个Web服务器上,但由appspot脚本处理。但是,每当我提交表单时,都会收到错误:

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

我有什么问题吗?此外,我在OSX上从Google App Engine Launcher部署了该应用程序。当我在Launcher上单击“运行”时,它在localhost:8080上运行,那么当它工作时我能看到“打印”吗?谢谢!

〜Carpetfizz

1 个答案:

答案 0 :(得分:1)

您需要将此添加到您的处理程序:

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

用您想要接受的原点替换星形符号(接受每个主机)。见this link