Forums

Specific users get 502-backend error on one specific view

Edit: It appears it was only in google chrome. I managed to talk him through switching browsers, and it works in internet explorer. It does however seem to be a weird error.

Hi!

I have created a simple chess app using Django for my grandfather and his brother to play easily, as they are not even remotely computer savvy, but when he tries to access the view which is supposed to supply the current game status he gets a 502-backend error, with a generic error page.

Myself I got the same error once, but it dissappeared and I assumed it was just a passing thing.

The chess retrieves a pgn via ajax from a view, http://python.torsjakk.com/getGameFen/ , this site however shows a generic error message to him, while I myself am able to access it via multiple computers and browsers without getting an error.

He can visit the main site just fine, http://python.torsjakk.com - but the ajax which retrieves from the getGameFen site receives the error page as well and thus it will load incorrectly.

There are no traces of any errors in my logs, and considering that it works for me, and also for one of my friends whom I asked to test it, I am unable to determine the cause.

I have tried some of the solutions I've found by googling "something went wrong 502 backend pythonanywhere", such as seeing if running "python wsgifilepath" returns any errors, but have been unable to have any success.

I hope you can help me?

It's interesting that it works in IE and not Chrome. It may be something to do with parallel requests to your web app, though they should be queued, and not discarded. Do you wait for the DOM to be loaded before your AJAX request and are there lots of elements (images, css, javascript) that need to be loaded for the page? Is your AJAX request very heavy in disk access or CPU use?

The request view is the following, which I believe is not cpu heavy at all. ChessGame contains just two CharFields which contain strings with the current chess game status as fen and as pgn. (i.e. 1. e5 e7 2. d5 d7 ...)

if (len(ChessGame.objects.all()) > 0)
    game = ChessGame.objects.all()[0]
    return HttpResponse(game.pgn);
else:
    return HttpResponse("No game found.");

My Ajax request run at an interval of 5 seconds, which I believe should be sufficient spacing, while still allowing them to play "live".

I don't believe the ajax is the problem though, since if he visits the page the ajax request tries to get normally, by entering the url into his browser, he gets the error rather than the correct response.

One possibility is that there was an error once on Chrome, and it's cached it. Could you try hitting shift-reload on it and seeing if that fixes the problem?

I have set cache : false in the ajax call, but I added that after he received the error the first time so I suppose it could still be cached. I'll have him try that next time we play if the error is still there.

Thank you for your speedy replies, love the service!

Thanks, glad you like the service!

I hope the force-refresh will sort things out, but please do let us know either way -- if it does fix it then perhaps we're not setting the right "no cache" headers on our error page. And if it doesn't then obviously we need to come up with some more suggestions :-)