当前位置: 动力学知识库 > 问答 > 编程问答 >

Seemingly Random 500 Internal Server Errors - Apache, Python CGI, AJAX

问题描述:

I have narrowed down the problem to the python weather module I created, but I still do not know why it is causing this trouble. I am using the requests module to get the xml file from Yahoo's weather API, and sometimes it will fail to verify the SSL certificate. As a temporary solution I have set verify=False, but I would really like to know if there is a better solution to this.

I am putting together a program for my Raspberry Pi that will display in a webpage. The basic idea is that the program shows the time, the current weather + a 5 day forecast, how long until the bus arrives at the stop near my apartment, and I haven't decided what will go in the 4th module on the dashboard.

Anyway, I am starting with the weather module and I have seen it work many times, but I keep getting seemingly random 500 errors from apache. I am using a python cgi and displaying the dashboard using python as the backend.

The main html page is sent from index.py, and I use a jquery file to issue an AJAX request to a weather module I created in python to get data from Yahoo's weather API. The AJAX request sends 3 GET requests to 3 python scripts that respond with the current temp, a condition code, and description.

Sometimes when I load the page I will get a 500 error for index.py in which case the whole page will not load. Other times every thing will load fine and all of the weather information will display properly. Yet other times one or more of the AJAX requests to the weather python scripts will return 500.

I have looked at the logs from Apache and there are some things that I do not understand that may be helpful in providing answers. Below is the log from one attempt at loading the page:

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] End of script output before headers: getCurTemp.py, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: Traceback (most recent call last):\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:/xampp1/htdocs/dashboard/scripts/getCurTemp.py", line 2, in <module>\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: import weather\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\xampp1\\htdocs\\dashboard\\scripts\\weather.py", line 4, in <module>\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: r = requests.get('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=******&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\Python27\\lib\\site-packages\\requests\\api.py", line 67, in get\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: return request('get', url, params=params, **kwargs)\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\Python27\\lib\\site-packages\\requests\\api.py", line 53, in request\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: return session.request(method=method, url=url, **kwargs)\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\Python27\\lib\\site-packages\\requests\\sessions.py", line 468, in request\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: resp = self.send(prep, **send_kwargs)\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\Python27\\lib\\site-packages\\requests\\sessions.py", line 576, in send\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: r = adapter.send(request, **kwargs)\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: File "C:\\Python27\\lib\\site-packages\\requests\\adapters.py", line 447, in send\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: raise SSLError(e, request=request)\r, referer: http://localhost/dashboard/index.py

[Tue Aug 23 10:54:44.526991 2016] [cgi:error] [pid 5888:tid 268] [client ::1:1377] AH01215: requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)\r, referer: http://localhost/dashboard/index.py

I am not sure what to make of any of this, especially since sometimes I can load the page with no issues at all. I see that the last thing in the log is something about SSL. Is this something that could only produce an error sometimes?

Am I just overloading Apache with too many requests too quickly?

I am using Apache 2.4 on a Windows XP machine to test all of this before uploading it to my Pi.

**Note: I starred out a section of the yahoo api query that shows up in the log for anonymity sake.

分享给朋友:
您可能感兴趣的文章:
随机阅读: