Home > Mobile >  404 error in old app that has worked for years
404 error in old app that has worked for years

Time:12-01

SimplifyConnections.appspot.com has worked for years but suddenly throws 404 errors that disallow the reading of existing map pins and of new map pins. This new failure occurs on both the deployed app and on the local sdk. You can experiment at the link by creating your own map pin and it will appear to be accepted, but when you refresh the link, your map pin is gone. Only my Log suggests there is an error (see below).

I have attempted to create simplified code that would fail in the same way but my simplified code fails from another error which I do not know how to circumvent: 405 Method Not Allowed; The method POST is disallowed for this resource. But I believe my code below may suggest the routing error I see in the log of the actual app.

I show next the logged routing error I now get.

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 -

My pseudo code is next.

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 (NB. in the 4th from last line "post" must be changed to "get" to avoid 405 error, but the real code is a "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>

I don't know how to show the actual code with any brevity, but I hope the example code gives enough information. I don't believe the mapping app is relevant to this error, but it does produce the real routing requests which are handled by the callback.

CodePudding user response:

  1. According to the documentation for webapp2, you need to define a POST method if you're executing a POST ...The Guestbook handler has a post() method instead of a get() method. This is because the form displayed by MainPage uses the HTTP POST method (method="post") to submit the form data. If for some reason you need a single handler to handle both GET and POST actions to the same URL, you can define a method for each action in the same class...

  2. For your routing, I'm curious as to why you're using details.txt and not just details. Do you think that could be the cause of your issue?

CodePudding user response:

The answer is embarrassingly simple. In the app.yaml handler needed to be changed to add .*.

handlers:

-url: /.*

script: mainapp.app

  • Related