Forums

504 Gateway Time-out

Hey Guys, I`m trying to open my web app but it keeps giving my this 504 Gateway time-out response. Do you have any ideia why this happening? Or how can I fix it? Tks for your help. JP

Hi JP -- sorry about that. We were doing an upgrade to PythonAnywhere around the time you posted this message, and I suspect that caused the problem. It looks like everything's OK now.

Hey GIles, seems I'm still facing some problem on this matter. Specially when I try to load http://jbtte.pythonanywhere.com/tjdf/default/index Could you take a look for me pls? tks JP

That's really strange -- it looks like it's working at the moment. It's a bit slow -- maybe 5 seconds to load -- but a page appears with the title "Tjdf".

Hi Guys, I have same problem with 504 timeout getway. There are a lot of bad response from server as 504, webdrive Firefox for selenium, 500 internal server error. is there any solution to improve my API usage? thenks

The 504 error means that a request took more than a few minutes to process.

Some background will probably help in explaining this:

When a request comes in to PythonAnywhere, it's put on a queue specific to your website. You have one or more worker processes, each of which goes through a loop where it waits for a request to appear on the queue, takes the request off, processes it, returns the response, and then goes back to waiting for new requests.

Free accounts get one worker process doing this, but with your paid account you have a couple.

A 504 error happens when the a request comes in, and no response is received from your code by our front-end web servers within a few minutes. There are two ways this can happen:

  • If your code takes a request off the queue, and then spends a few minutes processing it.
  • If your code is spending lots of time processing some requests that came in earlier, and so requests are going on to the queue but no worker processes are available to handle them.

So, the solution is to try to make your views work as quickly as possible. You mention Selenium -- are your views using it to access other sites? If so, you could have a problem if those other sites are running slowly, because that would in turn slow down your site. I'd suggest moving Selenium-based code out to scheduled tasks or something like that -- the data that you download with Selenium could then be put into a database and your web views could serve it up from there.