It looks like you're using a Python DB-API compatible driver. To get the best answer you should really include the library you're using and the database driver.
Either way, you've currently got an unsafe operation, ripe for some kind of unescaped SQL injection exploit.
First change your query to this:
b.query("select * from b where a=%s limit 1", c)
result = b.store_result()
WSGI wants just str() objects back, and you're returning instead tuples of values. You're returning text/html
so you probably want to do something like this:
def csvify(row):
return ",".join([str(col) for col in row])
start_response('200 OK', [('content-type', 'text/html')])
return ["<html><body><pre>"] + [ csvify(row) for row in results ] + ["</pre></body></html>"]
If you'd like to use yield, just create and return a generator instead of a list.
def csvify(row):
return ",".join([str(col) for col in row])
def my_response_generator(results):
yield "<html><body><pre>"
for row in results:
yield csvify(row)
"</pre></body></html>"
start_response('200 OK', [('content-type', 'text/html')])
return my_response_generator(result)
I would strongly recommend moving away from manually generating your own HTML and WSGI responses and look at using a simple framework like flask
to abstract away a lot of the boilerplate. A template system like jinja
can make this significantly better to read, write, maintain, and extend.