Forums

Error code: 502-loadbalancer

I have just upgraded my account from beginner to a Hacker level account, and I have started to receive errors. The site alternates between the standard Something went wrong :-( page with Error code: 502-loadbalancer at the bottom and

sqlalchemy.exc.OperationalError: (OperationalError) (2013, 'Lost connection to MySQL server during query')

The site is a Flask based site and the sqlalchemy errors are showing up in the server.log/error.log files. Reloading the site does not fix the issue.

Is there some kind of a wait time for the site to be upgraded from beginner to a paid account?

That's very strange; someone else reported a similar-sounding error earlier on today, and it certainly shouldn't happen. Did it start happening as soon as you upgraded? Or was there a delay?

There was a very short delay from when I upgraded. I had initially upgraded due to the error mentioned in:

https://www.pythonanywhere.com/forums/topic/502/

This states that authentication with OpenID is blocked while using a free account here. After upgrading it worked long enough for me to try it once. I was redirected to the google OpenID authentication page, the callback worked fine, although there was a small error in my python code. After fixing that error all I can get is the errors above.

So it could be possible that this started after the first time I reloaded my web service.

At the moment all I am getting is the 502 errors, with nothing being logged in any of the log files.

I can't see any 502 errors on your site?

If nothing's appearing in the error logs, it either means there's no errors, or that your web framework is silently swallowing the errors... Could it be some sort of debug mode?

I think I may have figured this one out, in the Flask tutorials it states to redirect the user to the 'next' url after successful login.

if g.user is not None and g.user.is_authenticated():                                                                                                                                                  
         flash('User was set to %r' % g.user)                                                                                                                                                              
         return redirect(oid.get_next_url())

If this url is the /login url then you will be in a situation where there is a redirect loop. After trying it again today it was alternating between the 502 error and a Chrome error stating there were too many redirects. To be safe I now state explicetly where I want the redirect to go, for example:

return redirect(url_for('index'))

Or I check to make sure the oid.get_next_url() is not the login page:

if oid.get_next_url().rsplit("/", 1) == "login":                                                                                                                                                  
    flash('prevented loop');                                                                                                                                                                      
    return redirect(url_for('index'))

It seems that the Error code: 502-loadbalancer message was masquerading the true problem which was a redirect loop.

The dreaded redirect loop! I've been caught by that myself, when experimenting with Mozilla Persona: Test-Driven Web Development with Python, authentication chapter

I just got this message:

Error code: 502-loadbalancer

When trying to get to http://www.pythonanywhere.com/ from http://blog.pythonanywhere.com/

again...:-(

P.S. I would have written to you in rhyme, but the last time I tried, you didn't get it because the feedback system wouldn't take my report.

The web server that runs PythonAnywhere had to have a little lie down. It woke up refreshed and ready to serve after a few minutes, though.

You'll be glad to know we have a fix in for the forum bug (it was all of one character!)

That's not a bug that's a bu...☺

Actually, that may be of interest. Did you know that this happens?

>>> print '{}1.50'.format('£')
£1.50
>>> print '{}1.50'.format(u'£')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128)
>>> print u'{}1.50'.format(u'£')
£1.50

I didn't, yet one more reason I try to keep myself in Py3k!!

I wonder if there has ever been a competition to locate the most odd/compelling single character bug.

OH, and that will teach you to use pounds versus dollars...;-)

j/k

Hi,

I started to receive 502-loadbalancer errors. Web log does not log anything.

Page is written in Flask. I moved from free to hacker recently

does it constantly do that? Or does it 502 sporadically? Looking at your webapp traffic, has it increased in the recent month?

i am working on the code of the page right now. I am the only one generating the traffic. Is there a way to debug this somehow? as i said there is no info in web logs

It looks that in my case the problem was that session / cookies files reached size 3777

Good catch! Yes, if the header of incoming requests passes a certain size (I think it's actually 4096 bytes in total, but there's overhead that might take it down to something closer to 3777) then the loadbalancer may well reject the request. It should have been rejecting it with a 431 error rather than a 502, though -- at least that would be easier to debug. We'll look into why that might be happening.

I'm getting this error too, likely for different reasons.

I'm running a Flask app that generates sometimes very long URLs using "url_for." if I use "return redirect(url_for(. . .)), I get the 502-loadbalancer error. If I return the URL to a site and then paste then paste it into a web browser, it works fine. I'm on Hacker as well.

Shorter URLs are not causing issues.

Any ideas?

The only solution I can think of is to use shorter URLs -- if there's data in them, perhaps store the data in the database somewhere and then put a key to that particular information somewhere in the URL?