【问题标题】:404 error in old app that has worked for years已运行多年的旧应用程序出现 404 错误
【发布时间】:2022-01-06 15:34:03
【问题描述】:

SimplifyConnections.appspot.com has worked for years 但突然抛出 404 错误,不允许读取现有地图图钉和新地图图钉。此新故障发生在已部署的应用程序和本地 sdk 上。您可以通过创建自己的地图图钉在链接上进行试验,它似乎被接受,但是当您刷新链接时,您的地图图钉就消失了。只有我的日志表明存在错误(见下文)。

我试图创建以相同方式失败的简化代码,但我的简化代码因另一个我不知道如何规避的错误而失败:405 Method Not Allowed;此资源不允许使用 POST 方法。但我相信我下面的代码可能会提示我在实际应用程序的日志中看到的路由错误。

接下来显示我现在得到的记录的路由错误。

INFO     2021-11-28 17:28:32,466 module.py:861] default: "GET /details.txt?place=Playground HTTP/1.1" 404 -
INFO     2021-11-28 17:29:18,511 module.py:861] default: "GET /details.txt?Action=add&lat=23.828670922688467&lng=-8.0815625&details=Brian&category=1&label=BS&place=Playground HTTP/1.1" 404 -

接下来是我的伪代码。

app.yaml

    runtime: python27
threadsafe: true

handlers:
- url: /
  script: mainapp.app



basic_scaling:
  max_instances: 1
  #idle_timeout: 5m

mainapp.py

import os
import logging
import webapp2
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template



class MainPage(webapp2.RequestHandler):
    def get(self):
        logging.info("MainPage:  ")
        self.response.out.write("pin in")
        template_values = {}
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
        

class Details(webapp2.RequestHandler):
    def get(self):
        logging.info("Details:  ")
        action = self.request.get("Action", "Detail")
        logging.info("action: %s " % (action))
        self.response.out.write("pin in")


app = webapp2.WSGIApplication(
                                     [('/', MainPage),
                                      ('/details.txt', Details)],
                                     debug=True)

index.html(注意,倒数第四行的“post”必须改为“get”以避免405错误,但真正的代码是“post”。)

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    </head>
<script>
function process(form) {
    var details = escape(form.data.value);
    var url = "details.txt?Action=add&name=" +name;

    // ===== send the data to the server

    downloadUrl(url, function(doc) {
        if (doc) 
        {markerID = doc; }
        });  


    alert("Your information has been processed.");

}

function downloadUrl(url, callback) {
 var status = -1;
 var request = createXmlHttpRequest();
 if (!request) {
   return false;
 }

 request.onreadystatechange = function() {
   if (request.readyState == 4) {
     try {
       status = request.status;
     } catch (e) {
       // Usually indicates request timed out in FF.
     }
     if (status == 200) {
     // next line altered: Text replaces XML
       callback(request.responseText, request.status);
       request.onreadystatechange = function() {};
     }
   }
 }
 request.open('GET', url, true);
 try {
   request.send(null);
 } catch (e) {
   changeStatus(e);
 }
};
</script>
<body>

<form name="myForm" action="#" onsubmit="return process(this)" method="post">
Name: <input type="text" name="name">
<input type="submit" value="Submit">
</form>




</body>

我不知道如何简洁地展示实际代码,但我希望示例代码能提供足够的信息。我不认为映射应用与此错误相关,但它确实会产生由回调处理的真实路由请求。

【问题讨论】:

标签: python google-app-engine


【解决方案1】:

答案非常简单。在app.yaml处理程序中需要更改添加.*

runtime: python27
threadsafe: true

handlers:
- url: /.*
  script: mainapp.app

basic_scaling:
  max_instances: 1

【讨论】:

  • 嗨@zerowords,请接受此答案以结束您的问题。
【解决方案2】:
  1. 根据 webapp2 的 documentation,如果您正在执行 POST,则需要定义 POST 方法...Guestbook 处理程序具有 post() 方法而不是 get() 方法。这是因为 MainPage 显示的表单使用 HTTP POST 方法(method="post")提交表单数据。如果出于某种原因您需要一个处理程序来处理对同一 URL 的 GET 和 POST 操作,您可以为同一类中的每个操作定义一个方法...

  2. 对于您的路由,我很好奇您为什么使用details.txt 而不仅仅是details。您认为这可能是您的问题的原因吗?

【讨论】:

  • 我知道为什么 POST 不合适。不过,这不是我的问题。我的问题是为什么会触发 404 错误。我正在使用 details.txt,因为返回的其他详细信息不是文本。
猜你喜欢
  • 1970-01-01
  • 2022-10-20
  • 1970-01-01
  • 1970-01-01
  • 2020-10-09
  • 2014-04-24
  • 2022-06-12
  • 1970-01-01
  • 2019-05-28
相关资源
最近更新 更多