Hello all,
i need some help
i recently changes pythoon 2.6 code => python 3.2.3 but my script although not producing any errors now doesnt display anything else but a blankpage at htp://superhost.gr
can you help?
I tried MySQLdb, pymysql, oursql, but nothing happens.
i still get a blank page. I dont know what else to try since i see no error.
When I look at your page and do a "show source" in my browser
it shows me the following:
<!--: spam
Content-Type: text/html
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
</table> </table> </table> </table> </table> </font> </font> </font>
One obvious error is that you are writing html text before the
"Content-Type: text/html" line. And whatever code is supposed
to create the content is not getting run.
can anyone suggest anything?
It is hard to help you because there is no code to look at.
Also, I looked at your web site a couple days ago after you
said you were getting a blank page, but I got a traceback
page. I realize your are working on the problem and changing
things but nobody wants to spend time looking for a problem,
only to find out you've changed the code and their time was
wasted.
Also, your requests for help are spread out over multiple
threads making it hard for anyone to figure out what you've
already tried and what the current state of your code and
problems are.
I haven't used MySql so I can't offer any specific help regarding
that, but I can say how I would try to attack your problem if it
were my problem.
First, Python 2 and Python 3 are two different languages. Code
written for Python 2 will not run under Python 3 (in general)
unless it is changed. So first, are you sure that the database
connector (dbi module) runs under Python 3? Are you sure it is
installed properly?
To answer this question definitively you can write a simple
Python program to import the dbi module, open a connection to
your database and execute a simple query.
Once you are sure you can access the database with Python 3
code, next is your cgi script code.
Try running your cgi script interactively.
But when you do this, remember that the environment that your
script sees is different when you run it interactively than
when Apache runs your script. When Apache runs your script
it might be using a different userid (which can affect what
files your script can open), there different environment variables
(like REMOTE_HOST which will be missing when you run interactively).
You can see the environment that exists when Apache is running
your script by creating a cgi script like:
------------
#!/bin/env python3
import cgi, os, sys
print("Content-type: text/html\n")
print("""\
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Python CGI Environment</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h2>Python CGI Environment</h2>
""")
print("Python %s<br>" % sys.version)
print("Current directory: %s<br><br>" % os.getcwd())
print("Environment Variables:<br>")
for k in sorted(os.environ.keys()):
print(" %s: %s<br>" % (k, cgi.escape(os.environ[k])))
print("</body></html>")
------------
Open that cgi script in your browser. You can also run it
interactively and you'll see many differences with what
you see in your browser.
When you run your failing cgi script interactively, you can
give it an argument that is the url of the cgi script. For
example, if you do:
cd ~me/public_html/cgi_bin/
python3 myscript.py '
http://superhost.gr/myscript.cgi'
the cgi module will parse the url argument and setup the right
values for the QUERY_STRING environment value that Apache would
normally set up.
There may be other problems resulting from the different interactive
environment. If I recall, at one point you were having an error
because REMOTE_ADDR was not present in the interactive environment.
Perhaps the best way to deal with that is to modify your code.
Foe example replace
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
with
try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except KeyError:
host = 'not available'
Then your script will be able to run interactively and you can
continue debugging the real problems in it. Of course there
may be other issue you have to fix as well but find and fix
them one at a time.
Add print statements to your code to find out where things are
going wrong. Don't trust your own thinking about the code!
If you think a variable should be 3 at some point in the code,
print it out and verify it!
After you get the program to generate html that looks ok, comment
out your debugging print statements (so that only html is printed),
redirect the html output into a file, them open the file in your
browser and see if it looks ok. If not, modify the code until
it does.
After you've got the script producing good output interactively
see if works from Apache as cgi script. If not, it should be
much easier now to find the problem since most of the other
problems have been fixed.
I can even provide host
ort user & pass for someone willing to take a look from the inside.
Sorry, but I don't use MySql so I probably wouldn't be much help.
You might consider posting (and updating when you change it!!) your
code to some public place on the internet like
http://pastebin.com
so that anyone who wants to try helping you has some code to look
at. Be sure to remove any userids and passwords in your code
before posting it publicly. And please don't post it to this
list because it is too big.