【问题标题】:Origin null is not allowed by Access-Control-Allow-Origin with Google App Engine App使用 Google App Engine 应用程序的 Access-Control-Allow-Origin 不允许 Origin null
【发布时间】:2013-09-20 00:43:20
【问题描述】:

我有一个在我自己的域上运行的网站,它有一个表单,其中包含一个指向我的 google appspot 域的操作。 app spot 应用正在运行一个非常简单的 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 部署了该应用程序。当我在启动器上单击“运行”时,它会在 localhost:8080 上运行,所以当它工作时我能看到“打印”吗?谢谢!

~地毯嘶嘶声

【问题讨论】:

    标签: python google-app-engine


    【解决方案1】:

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

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

    将星号(接受每个主机)替换为您要接受的来源。见this link

    【讨论】:

      猜你喜欢
      • 2012-03-22
      • 2012-06-07
      相关资源
      最近更新 更多