E
E
Evgeny Elizarov2012-11-12 09:51:32
Python
Evgeny Elizarov, 2012-11-12 09:51:32

Python: web print not working

I am a beginner, but in general the task is extremely simple: display the results of the query. It would seem that there are no problems. Just in case, I opened Google, everything is just as simple:

import MySQLdb

def index():
    try:
        con = MySQLdb.connect(host="localhost", user="###", passwd="###", db="counter")
        cur = con.cursor()
        cur.execute("SET NAMES `utf8`")
        cur.execute("SELECT count(*) as `count`, DATE(`date`) as `date` FROM `count` WHERE `type` = 'server' GROUP BY DATE(`date`)")
        result = cur.fetchall()
        for row in result:
            print(row)
            
    except MySQLdb.Error:
        print(db.error())

... and nothing is printed... Why doesn't print work? Even
print "Hello world"

does not work. Maybe I missed something somewhere?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
SeTeM, 2012-11-12
@SeTeM

Maybe they forgot to run the index() function?

A
alz, 2012-11-12
@alz

Try sys.stdout.flush()

A
alz, 2012-11-12
@alz

Votonoche ... And what is "from the browser" do not specify? I suspect that print will not help you here.

E
Evgeny Elizarov, 2012-11-12
@KorP

There is something like this in the log,
[Mon Nov 12 12:31:50 2012] [error] [client 93.91.12.20] mod_python.publisher: nothing to publish.
what could it mean? I'm dealing with python under the web for the first time, so sorry for stupid questions

P
Pavel Tyslyatsky, 2012-11-12
@tbicr

In theory, print will output the result to your server's stdout. But for the web, it's better to use logging (if this is a real application):

import logging
logging.info('Your message there')

I am sure that print works fine (at least prints an empty line) if stdout is standard without redirects.
So please tell us which server/framework you are using. How do you start your server. Maybe a stupid question, but the result is not displayed in the console or on the web page?

V
viatoriche, 2012-11-24
@viatoriche

I am more than sure that it is necessary to return data using the yield method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question