Error code: 502-backend

Hi, I am getting the error, Error code: 502-backend when I am trying to launch my webpage. Is there any fix to this?

Something went wrong :-(

This website is hosted by PythonAnywhere, an online hosting environment. Something went wrong while trying to load it; please try again later.

If this is your PythonAnywhere-hosted site, and you just reloaded it, then the problem might simply be that it hasn't loaded up yet. Try refreshing this page and see if this message disappears.

If you keep getting this message, you should check your site's server and error logs for any messages — you can view them from the Web tab inside PythonAnywhere.

If there's nothing in the logs, and you're sure your site is OK, then it might be a problem on our side. Drop us a line at, in the forums, or using the "Send feedback" link on the site, quoting the error code below.

Error code: 502-backend

Hi ravee119,

I wonder if it could be happening because of a low-level error when our wsgi server tries to load your app.

What happens if you open a bash console and run

python /var/www/

If that causes an error, you should try and fix it, and then do a "reload web app"...

Also -- make sure your app isn't trying to call flask's On PythonAnywhere, you just need to provide us with a valid wsgi application that we can import, and we run the actual wsgi server for you. if you try and run your own, you get problems...

(I took the liberty of commenting out a line saying in your source code, i hope you don't mind.)

Hi Harry,

I really don't mind you changing the code. Thank you very much for trying to help me. I found the error that I was doing and fixed it. I did have a function for @app.route('/')

It is running now.

@harry Maybe add 'Allow PA staff to fix your code' as an account option? Most people wouldn't mind, especially if it rescues them, but some might!


Yeaa.. that can be great option..

To fancy it.. you can even add a thums up and thums down button like we have in stackoverlow. ;)


@ravee119 I also appreciate the 'Related' links over on the right - often useful.

Actually I wonder how much benefit there is to PA in having their 'own' forums, versus only using SO? (is this sacrilege?)

@jgmdavies to be fair the PA staff fixed a config issue, not application code.

Don't worry, we won't touch or even look at anyone's code under normal circumstances without asking first. The problem in this case was that the error was causing outages for other users, so we really had to patch it urgently.

Re: Stack Overflow -- we figure that it's useful to have both. We keep an eye on SO posts and answer any stuff we see over there too. Some people seem to prefer one, others prefer the other.

@djangoguy - Thanks, it seemed to be 'source code' above. Anyway I wasn't worried myself - just thought an explicit option might be useful.

@giles - Variety is good! Just concerned that it's a slippery slope if you were tempted to keep adding features...

@harry @giles: You guys are doing an excellent job in providing support for the users. Thank you very much for that. Hope that most of the users are premium account holders. I am going to convert to premium as soon as my algorithm gets to a good shape.

One most important thing I observed in the site is that it is very simple to handle and the support that we get is awesome. Thank you guys.




Don't worry about us being tempted to add too many features to the forums. It took us 4 months before we added the ability to edit existing posts, and over a year before we decided to add email notifications ;-)

And we still don't have preview...☺

Good afternoon. There was an error Error code: 502-backend

The error occurs when you send a POST request to one of the pages on the test application, there is no such error on the production application. Application:

If you check your website's error log, you'll see that there's a message at the bottom relating to a POST request. It looks like you're using an SQLite database, and it's locked.

i got the same error 505 backend.please help me

i didn't get any errors in the error log

If you look on your "Web" tab, you'll see that there's an error message relating to your virtualenv -- it's using the wrong version of Python, 2.7 instead of 3.7. You need to re-create the virtualenv with the right Python version.

Hi... I'm getting the same 502-backend error. I have deleted the (which shouldn't have run anyway) and I deleted the last thing I added, anew route. The runs without an error. Please advise...

The access log reads: - - [23/Mar/2019:19:37:12 +0000] "GET / HTTP/1.1" 502 2393 "-" "python-requests/2.7.0 
CPython/2.7.12 Linux/4.4.0-1075-aws" "" response-time=0.001 - - [23/Mar/2019:19:37:33 +0000] "GET / HTTP/1.1" 502 2393 "-" "Mozilla/5.0 (Windows NT 10.0;      
Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "" 
 response-time=0.021 - - [23/Mar/2019:19:37:33 +0000] "GET /favicon.ico HTTP/1.1" 502 2393 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, lik e Gecko) Chrome/73.0.3683.86 Safari/537.36" "" response-time=0.000

[edit by admin: formatting]

I'm guessing that you've changed your code somehow since posting the above, as your site is currently showing a different kind of error in the logs -- sometimes a 499 and sometimes a 504. Both of these happen when your code takes longer than three minutes to respond to a request. Are you doing some kind of heavy processing in your view for the root URL?

Hmmm... The answer is no. There's a tiny call at the beginning to a PythonAnywhere database and then some preliminary processing, but it has never taken more than a few seconds to run. There is a more substantial call made in the update module, but I took all the hooks to that module out. (Or at least I think I did.)

I figured it out!

I read in a database at the beginning, as I said. But since I run this code both here and elsewhere, I have a config file that tells me to sshtunnel into the database if it's running outside your system. I mistakenly copied a local config file into Pythonanywhere. the 502 (and 504 and whatever else) apparently came from trying to tunnel into your system from your system. I guess that doesn't work... although the error is not entirely transparent. Working now... thanks for the lead.

hmm. glad you figured it out! so you think that trying to ssh tunnel into pythonanywhere from pythonanywhere caused your code to error? what was the error message that you were seeing in your error logs?

There were 502, 499 and 504 messages in the log. I was trying all kinds of things and none of those messages were too informative... but the messages did change. Note that one of the first things the program did was read off a db, if that helps. As soon as I stopped my "intratunnel" just by changing the config file, it worked right away.

That's very odd -- you should certainly be able to ssh from PythonAnywhere to PythonAnywhere, though (of course) it would add on unnecessary overhead.

One possibility that comes to mind is that someone else on the same physical server as you might have also been trying to ssh across, but was using the wrong password -- if we get repeated failed logins from a particular IP address, the SSH system blocks that IP for an hour. So conceivably someone else was failing to log in, and causing that particular web server to be blocked from SSH access -- which wouldn't cause problems normally, because people normally don't SSH internally, but would cause symptoms like you were seeing in your particular case.

That's possible... At one point my version of this site (the one housed offsite) stopped working as well. This would give a common cause....

If the problem with the offsite version happened at around the same time as you tried to log in over SSH with the wrong password a few times, then yes, that would certainly explain it.

Hi! I get the same error, i don´t now what happen, I was fine. Error code: 502-backend

It seems you also posted here with a more detailed message.

I also got the same error and my website runned smoothly for days untill i upgraded for a custom product. Please can you check what's going on.

@glx -- I think we corresponded over email earlier, at around the time you posted this question, and the problem you had was something different, so I won't post the details here as it would make this forum thread a little confusing.

Hello there, I cannot log in to the admin page. Gives 502-backend error. Please, can you help?

If you're using Python 3.7, there is a bug in the point version of the Python 3.7 that your account is using. You can either use Python 3.6, or we can update the system image for your account to a more recent on that includes a Python 3.7 where the bug is fixed. Note that if you want to update your system image any code that depended on old libraries may break (since the change may upgrade those python libraries), and that you will need to rebuild your virtualenvs, reload your web apps and start new consoles for the change to take effect. Let us know if you'd like us to update your system image.

Please. Python 3.8 support is not ready yet, I prepared my application with 3.7. But as you said, I got the error because I used version 3.7.7.

No problem. I have switched your system image.

Thank you very much, Glenn. Everything works great :)

Excellent, thanks for confirming!

Hello there, I cannot go to dashboard page, and the home page as well. It gives me 502-backend error. Please, could you help? Thanks.

Hello there, I cannot go to dashboard page, and the home page as well. It gives me 502-backend error. Please, could you help? Thanks.

Sorry for inconveniences. We experienced an outage this morning, by now everything should be sorted out and running. If you keep having this problem, please let us know!

hello i am getting Error code: 502-backend while iam trying to load tensorflow models in django backend views. I checked my errorlog there is nothing in it.In serverlog there is something but i dont get to understand why its coming.

How does something that you do not understand looks like? If error log is empty, maybe it rotated, so check yourlogfilename.log.1 file.

"Could not load dynamic library ''; dlerror: cannot open shared object file: No such file or directory","failed call to cuInit: UNKNOWN ERROR (303)" these are few errors in server logs .there is problem in loading tensorflow packages. I didn't face these while testing on local host django. here is link for my server log error

libcuda is a library to interact with Nvidia GPUs. We do not have GPUs on our servers so we do not have relevant libraries.

Those models do run on my pc cpu whats problem to run them here in backend

Your PC has a GPU with CUDA cores. PythonAnywhere does not have a GPU with CUDA cores, so if your model relies on a GPU, then it will not work on PythonAnywhere.

okay thanks for information pythonanywhere .

now tried it with tensorflow cpu version and i got this different error in my server is nothing in error logs

We have a help page with a warning about using tensorflow in a web app: