Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42371 > unrolled thread

Python 3.2.3 and my blank page

Started byΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
First post2013-03-31 07:03 -0700
Last post2013-03-31 13:10 -0700
Articles 10 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Python 3.2.3 and my blank page Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-31 07:03 -0700
    Re: Python 3.2.3 and my blank page feedthetroll@gmx.de - 2013-03-31 08:47 -0700
    Re: Python 3.2.3 and my blank page rurpy@yahoo.com - 2013-03-31 11:14 -0700
      Re: Python 3.2.3 and my blank page Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-31 12:12 -0700
        Re: Python 3.2.3 and my blank page rurpy@yahoo.com - 2013-03-31 12:46 -0700
          Re: Python 3.2.3 and my blank page Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-31 13:08 -0700
            Re: Python 3.2.3 and my blank page rurpy@yahoo.com - 2013-03-31 13:21 -0700
              Re: Python 3.2.3 and my blank page Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-31 13:34 -0700
      Re: Python 3.2.3 and my blank page Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-03-31 12:19 -0700
        Re: Python 3.2.3 and my blank page rurpy@yahoo.com - 2013-03-31 13:10 -0700

#42371 — Python 3.2.3 and my blank page

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-03-31 07:03 -0700
SubjectPython 3.2.3 and my blank page
Message-ID<18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com>
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.

[toc] | [next] | [standalone]


#42376

Fromfeedthetroll@gmx.de
Date2013-03-31 08:47 -0700
Message-ID<b2d34500-21a5-4ace-bed0-ab71ea8cb363@h11g2000vbf.googlegroups.com>
In reply to#42371
I like to feed trolls :-)

On 31 Mrz., 16:03, Νίκος Γκρ33κ <nikos.gr...@gmail.com> wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#42389

Fromrurpy@yahoo.com
Date2013-03-31 11:14 -0700
Message-ID<1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com>
In reply to#42371
On 03/31/2013 08:03 AM, Νίκος Γκρ33κ wrote:
> 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.

[toc] | [prev] | [next] | [standalone]


#42393

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-03-31 12:12 -0700
Message-ID<e6966b1a-c6a4-4cfb-8dd2-d3a8d5015adb@googlegroups.com>
In reply to#42389
Τη Κυριακή, 31 Μαρτίου 2013 9:14:43 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com έγραψε:
> On 03/31/2013 08:03 AM, Νίκος Γκρ33κ wrote:
> 
> > 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.

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

[toc] | [prev] | [next] | [standalone]


#42397

Fromrurpy@yahoo.com
Date2013-03-31 12:46 -0700
Message-ID<31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com>
In reply to#42393
On 03/31/2013 01:12 PM, Νίκος Γκρ33κ wrote:
> 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.

[toc] | [prev] | [next] | [standalone]


#42401

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-03-31 13:08 -0700
Message-ID<3efac1a0-ea1f-4d64-886a-9609be9babef@googlegroups.com>
In reply to#42397
Τη Κυριακή, 31 Μαρτίου 2013 10:46:57 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com έγραψε:
> On 03/31/2013 01:12 PM, Νίκος Γκρ33κ wrote:
> 
> > 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.


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 via cmd or via browser(blank page)

[toc] | [prev] | [next] | [standalone]


#42404

Fromrurpy@yahoo.com
Date2013-03-31 13:21 -0700
Message-ID<3035b123-3bd3-4046-b6f0-a0e598f50cbc@googlegroups.com>
In reply to#42401
On 03/31/2013 02:08 PM, Νίκος Γκρ33κ wrote:

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

[toc] | [prev] | [next] | [standalone]


#42405

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-03-31 13:34 -0700
Message-ID<0b9712c6-6788-4a3c-9e1f-a8bccf1c76b8@googlegroups.com>
In reply to#42404
Τη Κυριακή, 31 Μαρτίου 2013 11:21:21 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com έγραψε:
> On 03/31/2013 02:08 PM, Νίκος Γκρ33κ wrote:
> 
> 
> 
> > 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.

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

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

[toc] | [prev] | [next] | [standalone]


#42394

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-03-31 12:19 -0700
Message-ID<f7b94bbe-f5f4-420b-b8c0-c77d7dd1bb4e@googlegroups.com>
In reply to#42389
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!!

[toc] | [prev] | [next] | [standalone]


#42403

Fromrurpy@yahoo.com
Date2013-03-31 13:10 -0700
Message-ID<6ab68a12-d164-45e0-8ac9-2ba2c60d0463@googlegroups.com>
In reply to#42394
On 03/31/2013 01:19 PM, Νίκος Γκρ33κ wrote:
> 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?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web