Forums

Question about certain statements in Flask Error Log

I've got a small web app going in Flask. This is my first time doing this. I really love PAW, it makes it so easy! The app basically hits another service for data, slices and formats it and responds to the querying device with the formatted data. Most of the error log has the following line.

2013-05-01 22:41:53,491 :Starting new HTTP connection (1): proxy.server

Is this showing the connection going out to the other data service to get data or is this related to the incoming connection request?

The above statement is what I see mostly in the log. Every now and again I see the below. What does it mean? Should I be concerned? Is there something I should do to not get these errors?

2013-05-01 22:42:15,544 :IOError: write error
2013-05-01 22:42:15,544 :Traceback (most recent call last):
2013-05-01 22:42:15,544 :TypeError: unable to set HTTP status line

Thank you for any guidance.

The host proxy.server is the PA proxy server. As a free account holder, you're restricted to only making outgoing requests to sites on the whitelist. The PA developers consider requests for additions to this list so feel free to ask if the site you want to use isn't on there.

If you're using one of the standard HTTP libraries, chances are they've detected the proxy server from the http_proxy environment variable which PA sets for you - from the log message you posted above, it appears that's the case, so you shouldn't need to configure the proxy anywhere (indeed you shouldn't configure it, using it from the environment variable is the correct approach).

The later lines certainly indicate a problem of some sort which may be because you're trying to access a site not in the whitelist. The final error "unable to set HTTP status line" sounds like it's coming from uWSGI to me, which is the application PA uses to host web applications. At a guess I'd say that the earlier errors in your script means that it's bombing out early before returning a proper HTTP response and uWSGI is being unable to continue processing the request.

In short, I think something is going wrong, but without looking through your code in more detail it's hard to say what. As a starter, check whether the site you're trying to access is on the whitelist - if not, there's little point in looking at the other errors until that's resolved.

For anybody else's reference, here is the source file in uWSGI where that final error seems to be generated.

Cartoo - thank you for the response.

The site I am accessing is on the whitelist. The app works. It serves data as I expect. It is using requests to access the outside web site's API.

The HTTP connection occurs maybe 50 to 100 times or more, then one of those error messages occur. Perhaps something in Request is posting the HTTP message, which doesn't sound like an error message to me.

The io write error, I don't have a good clue. Maybe there is some unhandled case that is getting through flask to be sent out. I'll look into this and post code once I return to a computer with a keyboard.

Great to hear you're finding PythonAnywhere easy so far!

The Starting new HTTP connection error looks harmless to me, you can probably ignore it -- especially if your app is working as you'd expect.

One possibility for the unable to set HTTP status line error is that someone is connecting to your Flask app and then hitting the "Stop" button on their browser or navigating to another page before your app has had a chance to send a response -- the error would then be displayed when uWSGI tried to send the response to the browser and discovered that the connection had been closed. This tends to happen if you've got pages that are quite slow to respond (perhaps because they've got to do a lot of work to get the data from the other service you mention).

Do you think that might be it?

Giles - thank you too for the response. Yes, the scenario described could potentially be the case. In this case the app is serving information for Panic's Status Board. It could be that that app closed or maybe even the App itself timed out. I'll watch this. For now it seems like nothing to worry about.