Python 502 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
502 Bad Gateway Meaning
About Us Learn more about Stack Overflow the company Business Learn more about 502 bad gateway nginx hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
502 Bad Gateway Fix
the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do I debug please explain this 502 bad gateway error a HTTP 502 error? up vote 1 down vote favorite 1 I have a Python Tornado server sitting behind a nginx frontend. Every now and then, but not every time, I get a 502 error. I look in the nginx access log and I see this: 127.0.0.1 - - [02/Jun/2010:18:04:02 -0400] "POST /a/question/updates HTTP/1.1" 502 173 "http://localhost/tagged/python" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3" 502 police code and in the error log: 2010/06/02 18:04:02 [error] 14033#0: *1700 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: _, request: "POST /a/question/updates HTTP/1.1", upstream: "http://127.0.0.1:8888/a/question/updates", host: "localhost", referrer: "http://localhost/tagged/python" I don't think any errors show up in the Tornado log. How would you go about debugging this? Is there something I can put in the Tornado or nginx configuration to help debug this? python http nginx share|improve this question edited Jun 2 '10 at 23:54 asked Jun 2 '10 at 23:47 Bialecki 8,093226492 Most will find, this is the result when nginx fails to validate upstream headers (201 with content), or there are so many errors (Notices) logged that it breaks the 4k error buffer. –ppostma1 Jan 9 '14 at 16:56 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted The line from the error log is very informative in my opinion. It says the connection was refused by the upstream, it contains client IP, Nginx server config, request line, hostname, upstream URL and referrer. It is pretty clear you must look at the upstream (or firewall) to find out the reason.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack
504 Bad Gateway
Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack 502 proxy error Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up python catch HTTP
Http 504
502 error? up vote 0 down vote favorite I have met some 502 error and how can I make a client robust against 5XX errors by retrying the request once or twice if you receive one, that way even if they do http://stackoverflow.com/questions/2962439/how-do-i-debug-a-http-502-error occur, your software will continue running normally. My codes are here http://pastebin.com/YHpZQ9Z9 python exception share|improve this question asked Aug 7 '13 at 1:53 user2556720 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote You need to do something like: try: # code that can potentially throw a 502 except HTTPError as e: if e.code == 502: #put your retry logic here else print 'Failure: ' + str(e.reason) For more information, read the urllib2.HTTPError docs. share|improve this answer edited Sep 13 at http://stackoverflow.com/questions/18093373/python-catch-http-502-error 20:55 pzp 3,4741033 answered Aug 7 '13 at 2:07 Prahalad Deshpande 3,0881016 the error did not return 502, it return invalid JSON format. As I call from the API it return the JSON data. How can I make sure that I can call the method again when it reach the error ? –user2556720 Aug 7 '13 at 8:05 Could you elaborate? Is it that the API you call returned you an invalid JSON content and NOT an HTTP 502 error? If that is the case, then you would want to validate the response for ensuring that the API fetched the correct data - there is a reference link: alexconrad.org/2011/10/json-validation.html; however I have not tried the steps within the article. Having said this, it is still always a good practice to try-except on HTTP errors and print a meaningful information to the user –Prahalad Deshpande Aug 7 '13 at 8:31 when the api return when calling is suppose to return JSON, and it gave me a JSON error, that it cannot find any JSON format to read. This is because of the HTTP 502 error that return "cannot get key". Thats how the http 502 error comes in. Basically is they return cannot get key my code cannot detect JSON. Is there any way to let it run again to check for API ? –user2556720 Aug 7 '13 at 14:35 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign
reloaded Sometimes, if you https://help.pythonanywhere.com/pages/502BadGateway/ go and visit your site immediately after hitting the "Reload" button, you end up trying to access the site while it's still reloading, and that http://grokbase.com/t/python/python-list/0144dbgdw4/python-cgi-and-502-errors-under-iis can cause a bad gateway error. Make sure the spinner has stopped before viewing the site. Look for import errors or syntax errors in bad gateway your WSGI file If your WSGI file is totally broken, that can cause a 502 bad gateway error, and it wouldn't end up in the error logs. In almost all other cases, we should be able to catch exceptions and send them to your error logs (you have 502 bad gateway checked your error logs haven't you?) Don't use app.run() (for Flask) or try to run your own web server Flask's app.run() call tries to create its own web server, which is typically what you would use on your own machine. On our servers, we run web server processes for you (using uWSGI), so there's no need to use app.run(). Just provide the wsgi application as a variable called "application", and we'll do the rest. But if you try and call app.run(), it conflicts with our web worker and breaks stuff. Contact support if nothing else works We're always happy to help. Use the "send feedback" button, or post in the forums, or email us at support@pythonanywhere.com. Want to improve this page? Submit a pull request! Copyright © 2015 PythonAnywhere LLP — Terms — Privacy "Python" is a registered trademark of the Python Software Foundation.
for CGI scripting under W2KProfessional/IIS 5.0. I am working on a laptop that is acting as the webserver as well as my development machine. I am trying to learn Python...Every time I try to execute a test script either by direct URL or by a formPOST, I get a 502 error (Bad Gateway) in the server log file:19:47:46 127.0.0.1 POST /www_test/script/test.cgi 502My site has Read/Execute permission, and I have registered Python in theApplication Mapping area (as a Script Engine) of the IIS config tool for the.py and the .cgi extensions (and I have tried both).Any ideas on what I am doing wrong? Why would I be seeing a Bad Gatewayerror?Thank you,Peter reply Tweet Search Discussions Search All Groups Python python-list 2 responses Oldest Nested Owe André Jørgensen Peter, I got a word of advice for you! Get rid of that crappy IIS 5.0 and install the brilliant Apache Web Server! It'll give you a more readable error on what you're doing. The 502 error is something that has with the server environment to do, so you'd better configurate the server more properly. If you have, then I have got no clue. But then again, it qould be advisable to convert to the Apache server. Happy (bug)hunting! Andr? Owe André Jørgensen at Apr 4, 2001 at 4:27 pm ⇧ Peter, I got a word of advice for you!Get rid of that crappy IIS 5.0 and install the brilliant Apache Web Server!It'll give you a more readable error on what you're doing.The 502 error is something that has with the server environment to do, soyou'd better configurate the server more properly. If you have, then I havegot no clue.But then again, it qould be advisable to convert to the Apache server.Happy (bug)hunting!Andr? reply | permalink Peter J. Ungaro Andre, Actually, a great suggestion, as I am now running Apache 1.3.19 and I have CGI scripts working with Python now in this new environment. However, I also installed mod_python 2.7.2 per the Windows installation instructions and when I try to run a mod_python script, I get an Internal Server Error from Apache, and the following in the server log file: make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. [Wed Apr 04 16:55:50 2001] [error] [client Peter J. Ungaro at Apr 4, 2001 at 9:05 pm ⇧ Andre,Actually, a great suggestion, as I am now running Apache 1.3.19 and I haveCGI scripts working with Python now in this new environment.However, I also installed mod_py