Forums

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 support@pythonanywhere.com, 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/ravee119_pythonanywhere_com_wsgi.py

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 app.run(). 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 app.run() 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!

Jim

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. ;)

--Ravi

@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.

--Ravi

+1!

:-)

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: http://fedordev.fedorproxy.pp.ua

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 app.run (which shouldn't have run anyway) and I deleted the last thing I added, anew route. The wsgi.py runs without an error. Please advise...

The access log reads:

4.204.25.127 - - [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" "54.204.25.127" response-time=0.001
74.70.168.73 - - [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" "74.70.168.73" 
 response-time=0.021

74.70.168.73 - - [23/Mar/2019:19:37:33 +0000] "GET /favicon.ico HTTP/1.1" 502 2393 "http://www.wongpool.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, lik e Gecko) Chrome/73.0.3683.86 Safari/537.36" "74.70.168.73" 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 'libcuda.so.1'; dlerror: libcuda.so.1: 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 pastebin.com/bUUTZwxa.

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 log.link https://pastebin.com/bgHFqV46.there is nothing in error logs

We have a help page with a warning about using tensorflow in a web app: https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/

My site is not loading and I'm getting a 502 - backend. Can you guide me if this is something on your side or my side? https://storloft.pythonanywhere.com/en/ . Thanks!

If you check out the server log for your site, you'll see a (not very clearly formatted) error relating to a segmentation fault -- that means that the Python interpreter itself has crashed.

Are you using a virtualenv? If so, is it one that you created on PythonAnywhere? Virtualenvs are not portable from one machine to another, and the most common cause of segmentation faults is when someone builds a virtualenv on their own machine and then copies it up to PythonAnywhere; the env winds up trying to load C libraries of a different version to the ones it expects, and Python crashes.

I am pretty sure I am not doing anything of that sort. I created a virtual environment on PA only which I have been using.

There is an error note above your segmentation fault error about how you're installing psycopg. Make sure you're following that and rebuild the virtualenv with that in mind.

My site is not loading and I'm getting an Error code: 502-backend. Can you assist me if this is something on your side or my side? The site is hansa.my. Thank you very much.

I currently have the same and our site has been unreachable for at least the past 2 hrs. No code changes were made by us so I'm guessing its something on the PA side. Their site was also down for a bit today.

Same here, no code change was made. But the site was back 30mins ago.

We have the same problem since around 2:00 am. Site down, 502 error is displayed. No code changes.

  • error.log: 2023-10-04 02:19:12,741: OSError: write error
  • server.log: 2023-10-04 02:36:50 chdir(): Input/output error [core/uwsgi.c line 2625]
  • server.log: 2023-10-04 07:00:48 uwsgi_master_manage_emperor()/read(): Bad file descriptor [core/emperor.c line 2442] 2023-10-04 07:00:48 lost connection with my emperor !!! 2023-10-04 07:00:48 VACUUM WARNING: unix socket /var/sockets/xxx/socket changed inode. Skip removal

Any help is much appreciated!

What are the domains? Send that to support@pythonanywhere.com if you don't want to post it on public forums.

@fyl: https://www.fyndery.de/

Let me know, if there is something we can do.

Hello! My site https://www.museumsun.org/ also broke. Displays the error Error code: 502-backend

2023-10-04 12:34:27 Respawned uWSGI worker 2 (new pid: 503) 2023-10-04 12:34:27 spawned 2 offload threads for uWSGI worker 2 2023-10-04 12:34:33 Wed Oct 4 12:34:32 2023 - *** HARAKIRI ON WORKER 3 (pid: 497, try: 1) *** 2023-10-04 12:34:33 Wed Oct 4 12:34:32 2023 - HARAKIRI !!! worker 3 status !!! 2023-10-04 12:34:33 Wed Oct 4 12:34:32 2023 - HARAKIRI [core 0] 10.0.0.83 - GET / since 1696411771 2023-10-04 12:34:33 Wed Oct 4 12:34:32 2023 - HARAKIRI !!! end of worker 3 status !!! 2023-10-04 12:34:33 DAMN ! worker 3 (pid: 497) died, killed by signal 9 :( trying respawn ... 2023-10-04 12:34:33 Respawned uWSGI worker 3 (new pid: 506) 2023-10-04 12:34:33 spawned 2 offload threads for uWSGI worker 3 2023-10-04 12:34:40 Wed Oct 4 12:34:40 2023 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /static/css/owl.carousel.css (ip 10.0.0.83) !!!....

We had an issue on the storage server that your account uses. We have fixed it now, so everything should be working again.

Hi guys, the error is back again.

The site is not loading and I'm getting an Error code: 502-backend.

We had another hardware issue around that time. Sorry for the inconvenience!

Hi guys, I am getting an error of Error code: 502-backend on both my websites. No code changes were made on either of them. Last time we checked was on Monday and they were working perfectly. Yesterday was a holiday and today when I am trying to load them it refuses to load and this error is shown.

Your help would be really appreciated.

Guys same thing load balancer error. Pls these errors are getting more frequent don’t make us change your service

Guys pls there has not been any change in the code and yesterday was working what happening?

Hi there, are you still seeing this error?

yes

Sorry about that! There was a hardware issue on one of our postgres servers. We're improving our alerting system so this doesn't go unnoticed next time.

Sorry to rehash this 502 error but I am getting despite commenting out:

if name == "main": #app.run(debug=False)

And adding the line in the /var/www/adambh_pythonanywhere_com_wsgi.py: from my_flask_app import app as application # noqa

Would appreciate any help as I cannot move on at the moment.

I figured it out: STEP 1: Changed the the main.py file to called 'app.py' STEP 2: Changed the wsgi.py file with the following line: from app import app as application # noqa: F401

  • Hope that helps anybody here

Also commend out anything in your app.py file that uses something like app.run(debug=False)

I think the servers are down again. I am getting a 502 now as well.

I think servers aren't working. I got 404 error after restarting my webpage and error saying file does not exist. The files tab does not work (I am praying that my files were not deleted)

yes, me too

i also cannot access my files, it gives me 404

web related: My app keeps reloading. It shows error "Your webapp took a long time to reload. It probably reloaded, but we were unable to check it." and my site does not respond. (Why am I writing this, proably everyone knows)

Yes, we had an issue with one of the storage servers around the time you posted.

Hello friends. On my website https://www.museumsun.org/ the error is Error code: 502-backend. What is the problem?

Hey friends, I too am also receiving Error code: 502-backend for my website https://www.pythonfordatascience.org/ and am having issues identifying the problem/solution.

  • Python version is 3.7
  • Reloaded the website: checked at 30 min, 45 min, 1 hour marks, and issue persists
  • Domain register is up-to-date
  • DNS Propagation Checker shows all is well with the CNAME
  • In server log, I see "!!! uWSGI process 1 got Segmentation Fault !!!"

Getting 502 backend error, is this a temporal issue/maintenance?

@museumsun1, @coreyb, @IGBotsKEK -- your accounts were all updated from our old "earlgrey" system image to the newest "haggis" one on Tuesday; we've sent you a number of emails over the last year so that you would know what changes to make and how to make them in advance. If you check your email for messages with subject lines including ACTION REQUIRED: "earlgrey" system image end-of-life, you'll find the details.

Actually, now I think about it, it'll probably save you time if I copy/paste the most recent one in here:


Your account "USERNAME" uses a system image called "earlgrey" to run your code. In one week, "earlgrey" will no longer be available and your account will be switched to a newer system image. This is likely to require changes to your code, as otherwise it will no longer run. You can update the system image now, at a time that you control, and find out if your code needs any changes to keep working.

The system image is essentially the version of the underlying operating system -- it determines which system libraries you have available, which versions of Python, and which pre-installed Python packages. "earlgrey" was released a very long time ago, and is based on Ubuntu 16.04, with support for Python versions up to 3.7. Our most recent system image, "haggis", is based on 20.04 with Python supported up to 3.10, and of course all of the pre- installed libraries like Django and Flask are much more recent too.

You can change your system image to a new one (and back again) at any time, without any risk to your own files or data -- however, because newer system images have newer versions of everything, your code might need modification to run with the new system image (that's why we don't silently upgrade you in the background when we release a new system image -- we don't want to break your code if it's working).

This help page has all of the details about changing your system image:

https://help.pythonanywhere.com/pages/ChangingSystemImage

Because the "earlgrey" system image's OS is so old, and the Python packages and versions likewise, it's not longer a fully-secure operating system. So in one week it will no longer be available and your account will automatically be updated to use the most recent system image -- we wanted to give you time to switch over at a time you control and to make any changes required, which is why we're emailing you about it now.


Hopefully that has all of the information you need, but drop us a line at support@pythonanywhere.com if you have problems getting things up and running again.

Getting 502 backend error, is this a temporal issue/maintenance?

Hi there -- I see that we have received several emails from you about this, and have replied to them -- are you not getting them?

Either way, it is the same issue as the one in my post above.

NO

Sorry, can I ask what that is regarding?

@giles Thank you for posting the message, the solution was straight forward for myself.

That's always good to hear!