Forums

How to debug a 502 - Bad Gateway

I'm wondering how to debug this kind of error.

POST http://www.myurl.com/toto 502 (Bad Gateway).

This happen on some sort of environment (not mine), following an AJAX post request like this:

$.ajax({
        url: '/toto',
        type: 'POST',
        data: formData,
        cache: false,
        async: true,
        processData: false,
        contentType: false,

    success: function (result) {
      console.log(result);
    }
  });

Is the bad gateway coming from a pythonanywhere-hosted web app? If so, is there anything in the error log?

Yes, it is my web app hosted on PythonAnywhere. And no, there's nothing in the error log, I can only see the error in the person's browser javascript console.

All of your web apps seem to be working and responding and a 502 means that (to simplify a little bit) we couldn't find the web app you were trying to hit. Make sure that you're actually posting to the URL you think you're posting to.

I was able to get the error code from the server.

Error code: 502-loadbalancer

Can you share a URL that reproduces the problem? Does it happen every time, or only infrequently?

One possibility is that, when you hit "reload" on your web app, there's a short time frame (20-30s) during which incoming requests might see a 502...

Actually it happens only on my friend's computer/environment (which is quite similar to mine but apparently not), but it happens all the time for him. I've never seen this on my computer or any other beside his.

that is baffling. and it's only happening on ajax requests? does it happen in all web browsers on your friends' computer? which have you tried?

Yes it only happens for that ajax request. I've tried on Chrome and Safari.

That is strange. The only thing that I can think of is that something on your friend's machine or on his network is messing with that ajax request and not the other requests.