Python 3.2.3 and my blank page

  • Thread starter Íßêïò Ãêñ33ê
  • Start date
Í

Íßêïò Ãêñ33ê

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 blank page 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.

can anyone suggest anything?

I can even provide host:port user & pass for someone willing to take a look from the inside.
 
F

feedthetroll

I like to feed trolls :)

Hello all,
Hello Ferrous Cranus [3]!
...
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.
Well, the output of your cgi is:
<!--: 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>

This is not valid html. Therefore the browser does not render
anything.
can anyone suggest anything?
Learn html [1] and python [2], read your code. Find out, why most of
your html-output does not get into the response. Solve the reasons.
Done.
I can even provide host:port user & pass for someone willing to take a look from the inside.
I'm sure it depends what you are willing to pay.
[Sorry, I forgot. You are looking for someone, who does your work
(which you are payed for because aou are a hoster) for free.]


[1] https://www.google.at/search?q=learn+html+online
[2] https://www.google.at/search?q=learn+python+online
[3] http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm
 
R

rurpy

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 blank page 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:port 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.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 31 Ìáñôßïõ 2013 9:14:43 ì.ì.. UTC+3, ï ÷ñÞóôçò (e-mail address removed) Ýãñáøå:
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:port 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.

Firsly, thank you for your willing to help me.

i wrote, uploaded an chmoded test.py and you can see the cgi enviromental table here: http://superhost.gr/cgi-bin/test.py

All values seem okey, so it really isnt somehting wrong with the cgi enviroment.

Also i chnagen the host line to what you suggestes so interactive prompts will not give errors.

Please take a look the values to see if something not look ok and i 'am about to create another trest script to check if i can pefrom a simple mysql query with python 3.2.3 just to make sure the MySQLdb connector work ok with 3.x
 
Í

Íßêïò Ãêñ33ê

I just tried the testmysql.py script:

#!/usr/bin/python3
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, re, os, sys, socket, datetime, MySQLdb, locale, random, subprocess



# connect to database
con = MySQLdb.connect( db = 'nikos_metrites', host = 'localhost', user = 'nikos_nikos', passwd = 'tiabhp2r#', init_command='SET NAMES UTF8' )
cur = con.cursor()

print ( "Content-type: text/html; charset=utf-8\n" )


# =================================================================================================================
# if extra string is attached to the URL is 'log' then show explicit page log and exit
# =================================================================================================================

cur.execute('''SELECT hits FROM counters''')
data = cur.fetchall() #URL is unique, so should only be one

for item in data:
print( item )
===================


it works, as you can see at: http://superhost.gr/cgi-bin/testmysql.py

so MySQLdb mpodule does work for Python3 !!!!!

so mysql connector is not the problem.

but hwta is it then i get no errors!!
 
R

rurpy

Firsly, thank you for your willing to help me. i wrote, uploaded an
chmoded test.py and you can see the cgi enviromental table here:
http://superhost.gr/cgi-bin/test.py All values seem okey, so it
really isnt somehting wrong with the cgi enviroment. Also i chnagen
the host line to what you suggestes so interactive prompts will not
give errors. Please take a look the values to see if something not
look ok and i 'am about to create another trest script to check if i
can pefrom a simple mysql query with python 3.2.3 just to make sure
the MySQLdb connector work ok with 3.x

I didn't mean that there was anything *wrong* with your cgi
environment, only that it is *different* than your interactive
environment.

It is easier to debug code in an interactive environment than a
cgi one so you want to do as much debugging interactively as possible,.
But because the environments are different your code will behave
differently. Knowing what is different between the two environments
will help you know if an error is due to a real problem in your
code, or is just due to the different environment. And it will
help you setup your interactive environment to be as close as
possible to the cgi one.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 31 Ìáñôßïõ 2013 10:46:57 ì.ì. UTC+3, ï ÷ñÞóôçò (e-mail address removed) Ýãñáøå:
I didn't mean that there was anything *wrong* with your cgi

environment, only that it is *different* than your interactive

environment.



It is easier to debug code in an interactive environment than a

cgi one so you want to do as much debugging interactively as possible,.

But because the environments are different your code will behave

differently. Knowing what is different between the two environments

will help you know if an error is due to a real problem in your

code, or is just due to the different environment. And it will

help you setup your interactive environment to be as close as

possible to the cgi one.


But i look the code and run python via interactive prompt and it says it has no error.

So i don't have a clue on what i still need to try since i get no error viacmd or via browser(blank page)
 
R

rurpy

I just tried the testmysql.py script:
[...snip code...]

I hope no one who reads this list also has access to your database
and that you don't use that username/password anyplace else.
it works, as you can see at:
http://superhost.gr/cgi-bin/testmysql.py
so MySQLdb mpodule does work for Python3 !!!!!
so mysql connector is not the problem.
but hwta is it then i get no errors!!

Get no errors from what? The original script you were having
trouble with? Are you running it by using your browser or
from interactively in a terminal window?

I probably should have asked this before, but can do you have
shell access to the script? Can you run it interactively in
a terminal window?
 
R

rurpy

But i look the code and run python via interactive prompt and it says
it has no error.

Does it produce any output? Is that output the right html? That is, if
you save the html to a file and open that file in a browser, does it look
right?
So i don't have a clue on what i still need to try since i get no
error via cmd or via browser(blank page)

I have no clue either because I don't know what output you are getting
when you run the script interactively, nor do I know what the code is
that you are running.
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 31 Ìáñôßïõ 2013 11:21:21 ì.ì. UTC+3, ï ÷ñÞóôçò (e-mail address removed) Ýãñáøå:
Does it produce any output? Is that output the right html? That is, if

you save the html to a file and open that file in a browser, does it look

right?







I have no clue either because I don't know what output you are getting

when you run the script interactively, nor do I know what the code is

that you are running.

I think i have mase some progress and it seems that the reason *perhaps* isencoding issues.

look at http://superhost.gr now and biew its source too.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top