No errors displayed but a blank screen instead

This is the place for queries that don't fit in any of the other categories.

No errors displayed but a blank screen instead

Postby NikosGr » Thu Mar 28, 2013 6:35 pm

Hello and iam happy to be here,

I wanted to make my website running Python 3 which is more new and bette:)

i treid to execute metrites.py via my jailed shell, please take a look if i'am not tiring you and maybe you can see if there is nothign wrong because i dont see nayhting.

The gethostbyaddr at the end its because the script run in cmd instead of in a browser.
Please help, its alkmost ready to run correctly!


Code: Select all
 
nikos@superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py
<!--: 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><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#6622aa">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>KeyError</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial">Python 3.2.3: /usr/bin/python3<br>Thu Mar 28 09:41:53 2013</font></td></tr></table>
   
<p>A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.</p>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big>&nbsp;</big><a href="file:///home/nikos/public_html/cgi-bin/metrites.py">/home/nikos/public_html/cgi-bin/metrites.py</a> in <strong><module></strong>()</td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;&nbsp;26</small>&nbsp;userform&nbsp;=&nbsp;form.getvalue('userform')<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;&nbsp;27</small>&nbsp;<br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt>=&gt;<small>&nbsp;&nbsp;&nbsp;28</small>&nbsp;host&nbsp;=&nbsp;socket.gethostbyaddr(&nbsp;os.environ['REMOTE_ADDR']&nbsp;)[0]<br>
</tt></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;&nbsp;29</small>&nbsp;date&nbsp;=&nbsp;(&nbsp;datetime.utcnow()&nbsp;+&nbsp;timedelta(hours=2)&nbsp;).strftime(&nbsp;'%y-%m-%d&nbsp;%H:%M:%S'&nbsp;)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;&nbsp;30</small>&nbsp;userinfo&nbsp;=&nbsp;os.environ['HTTP_USER_AGENT']<br>
</tt></font></td></tr>
<tr><td><small><font color="#909090">host <em>undefined</em>, <strong>socket</strong>&nbsp;= &lt;module 'socket' from '/opt/python3/lib/python3.2/socket.py'&gt;, socket.<strong>gethostbyaddr</strong>&nbsp;= &lt;built-in function gethostbyaddr&gt;, <strong>os</strong>&nbsp;= &lt;module 'os' from '/opt/python3/lib/python3.2/os.py'&gt;, os.<strong>environ</strong>&nbsp;= environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'})</font></small></td></tr></table>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big>&nbsp;</big><a href="file:///opt/python3/lib/python3.2/os.py">/opt/python3/lib/python3.2/os.py</a> in <strong>__getitem__</strong>(self=environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}), key='REMOTE_ADDR')</td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;448</small>&nbsp;<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;449</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;__getitem__(self,&nbsp;key):<br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt>=&gt;<small>&nbsp;&nbsp;450</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;=&nbsp;self._data[self.encodekey(key)]<br>
</tt></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;451</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;self.decodevalue(value)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;452</small>&nbsp;<br>
</tt></font></td></tr>
<tr><td><small><font color="#909090">value <em>undefined</em>, <strong>self</strong>&nbsp;= environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}), self.<strong>_data</strong>&nbsp;= {b'CLASSPATH': b'.:/usr/local/jdk/lib/classes.zip', b'CVS_RSH': b'ssh', b'EDITOR': b'pico', b'GREP_COLOR': b'1;32', b'GREP_OPTIONS': b'--color', b'G_BROKEN_FILENAMES': b'1', b'HISTSIZE': b'5000', b'HOME': b'/home/nikos', b'HOSTNAME': b'menara.websitewelcome.com', b'INPUTRC': b'/etc/inputrc', ...}, self.<strong>encodekey</strong>&nbsp;= &lt;function encode&gt;, <strong>key</strong>&nbsp;= 'REMOTE_ADDR'</font></small></td></tr></table><p><strong>KeyError</strong>: b'REMOTE_ADDR'
<br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>args&nbsp;=
(b'REMOTE_ADDR',)
<br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>with_traceback&nbsp;=
&lt;built-in method with_traceback of KeyError object&gt;


<!-- The above is a description of an error in a Python program, formatted
     for a Web browser because the 'cgitb' module was enabled.  In case you
     are not reading this in a Web browser, here is the original traceback:

Traceback (most recent call last):
  File "metrites.py", line 28, in &lt;module&gt;
    host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
  File "/opt/python3/lib/python3.2/os.py", line 450, in __getitem__
    value = self._data[self.encodekey(key)]
KeyError: b'REMOTE_ADDR'

-->


Please help i don't know what else to try.
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby KHarvey » Thu Mar 28, 2013 8:05 pm

Without delving too far into your code, have you checked your Apache logs error logs?

Your HTML is a little hard to read as well especially with all of the &nbsp.

If the logs don't show anything than I would start to break down the code. Start by clearing everything after
Code: Select all
<tr><td bgcolor="#d8bbff"><big>&nbsp;</big><a href="file:///home/nikos/public_html/cgi-bin/metrites.py">/home/nikos/public_html/cgi-bin/metrites.py</a> in <strong><module></strong>()</td></tr>
<tr><td><font color="#909090"><tt>&nbsp;&nbsp;<small>&nbsp;&nbsp;&nbsp;26</small>&nbsp;userform&nbsp;=&nbsp;form.getvalue('userform')<br>

Until you find which piece.

Or for testing hard code your os.environ['REMOTE_ADDR'] and try running at the command line again to see if it generates any errors.
KHarvey
 
Posts: 34
Joined: Tue Mar 19, 2013 5:13 pm
Location: US

Re: No errors displayed but a blank screen instead

Postby NikosGr » Thu Mar 28, 2013 8:27 pm

maybe the error is that MySQLdb isnt yet supported in Python 3.2.3 ?

Should i have the linux admin at hostgator.com install 'pymysql' pure python connector instead?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Thu Mar 28, 2013 9:39 pm

The error is caused because the code is trying to access an environment variable called REMOTE_ADDR.
It looks like you haven't created it.

For future reference, posting your code, and not just the output, will make it easier for others to help you.

P.S. Your title says 'No errors displayed but a blank screen instead', but what you have posted is an error formatted as HTML.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Thu Mar 28, 2013 9:59 pm

stranac wrote:The error is caused because the code is trying to access an environment variable called REMOTE_ADDR.
It looks like you haven't created it.

For future reference, posting your code, and not just the output, will make it easier for others to help you.

P.S. Your title says 'No errors displayed but a blank screen instead', but what you have posted is an error formatted as HTML.



No its not that i tried to put it out and still blank. host is a warnign because the code run in cmd and not in browser. here is the code:

I have attched the metrites.py for you to see.

Thank you for helping me.
Attachments
metrites.txt
this is metrites.py cgi script
(9.12 KiB) Downloaded 59 times
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Thu Mar 28, 2013 10:20 pm

NikosGr wrote:No its not that i tried to put it out and still blank.


If you've fixed that part, the error should have changed.
So post the error you're getting now.
It's pretty much impossible for me to guess what's wrong without seeing the error message.

Also, as a somewhat off-topic note, you should consider using a web framework instead of raw cgi.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 7:33 am

I completely removed the host=... line and stil the blank screen si there.

are we sure that MySQLdb is supported in python 3.2.3 myb that cause the error?

Can you please run tmy code i ppsted to your enviroment to see that it runs ok to your system?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 7:42 am

Well nto this is not the error, i uses to had MySQLdb as a conenctor but even withat that i still see a blank webpage without no errros. Then i had a suspision that perhaps MySQLdb isnt't supported in Python 3.2.3 so i decided to try pymysql but it wasnt there.

I asked at hstgator support to install that module for me since iam not familiar with linux very much or pip but i got this response just now.




> Hello again,

Per your request, a virtual environment has been created for you. You can find local Python binaries in:

/home/nikos/bin

Unfortunately the pymysql module cannot be installed using pip or easy_install and must be installed manually. There is no indication that this module in any way requires Python 3. Is there a particular reason you must use Python 3 instead of a version which supports the modules that you need? Given that the modules you need are better supported by earlier versions of Python, it's not clear to me why we're trying to use Python 3 instead.

If you would still like us to proceed with manually installing the pymysql module for the local version of Python under the nikos account, we will be happy to give it a try but there will be a one-time charge of $35.00 for the installation. I would recommend using an earlier version of Python which is compatible with the modules that you need, but it is certainly up to you. Please let us know how you would like to proceed.

So, just to make sure that MySQLdb isnt causeing the probkem can someone, perhaps you that is familiar with linxu conenct to my jailed shell account and install manually the 'pymysql' module because i dont know how to do it and i cannot afford to pay ath linux admin because iam unemployed.

please i can providr ou with user and pass for my jailed shell access for someone ti install it manually.
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby metulburr » Fri Mar 29, 2013 9:30 am

we will be happy to give it a try but there will be a one-time charge of $35.00 for the installation

anybody willing to pay that rather than do the research of how to do it is dumb. Maybe i should just become a host, and start charging people for something that takes a few seconds to do.

upon searching i found numerous places that say MySqldb is not yet ported to python3. I also found some that say it has been abandoned. I dont know how accurate this is though.

you would install it like any other 3rd party module, except on the server.
http://code.google.com/p/pymysql/downloads/list
download, extract, change into directory, and execute:
Code: Select all
sudo python3 setup.py install

if that is successful then self test it
Code: Select all
metulburr@ubuntu:~$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>>
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1472
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 10:02 am

You are absolutely right,

Code: Select all
nikos@superhost.gr [~/www/PyMySQL]# sudo python3 setup.py install
sudo: unable to mkdir /var/db/sudo: No such file or directory

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for nikos:
nikos is not in the sudoers file.  This incident will be reported.
nikos@superhost.gr [~/www/PyMySQL]#


is there still a way to run it?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Fri Mar 29, 2013 1:13 pm

NikosGr wrote:are we sure that MySQLdb is supported in python 3.2.3 myb that cause the error?

We can't be sure what's causing the error without seeing the error output.

As for your install error, it's not a surprise the host isn't letting you run sudo.
This should work for a local install:
Code: Select all
python setup.py install --user


But I would recommend not bothering with MySQLdb, and using oursql instead, I hear good things about it.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 2:46 pm

Tahnk you very much the local type of instalation worked okey!

Now i ahve switched from problemmatic 'MySQLdb' to 'pymysql'

but immediately after this change i get thefollowing error displayed at http://superhost.gr
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Fri Mar 29, 2013 8:15 pm

According to the README file on pymysql's github, you need to run the build-py3k.sh script if you want to use it with python 3.

I still think oursql is a better alternative, though.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 8:31 pm

Why you consider 'oursql' better than 'pymysql' which is a pure python mysql connector?

Also do i have to uplaod and run this .sh script just by itself or with thr others files as well?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby NikosGr » Fri Mar 29, 2013 8:44 pm

I have manages to install the script okey but the same error that appeared continue to appear, i dont know what else to try.
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Fri Mar 29, 2013 9:34 pm

NikosGr wrote:Why you consider 'oursql' better than 'pymysql' which is a pure python mysql connector?

server-side cursors, real parametrization, data streaming, speed...
NikosGr wrote:I have manages to install the script okey but the same error that appeared continue to appear, i dont know what else to try.

Sorry, I don't know what else to suggest, except maybe trying to ask in a specialized place, like the pymysql user group.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Sat Mar 30, 2013 8:05 am

Okey i decided to follow your advice and use 'oursql' connector isntead.

i downlaoded the .tar.gz from the link you given me uploded to remote host and extracted.

Can you please also tell me the process of installing it?
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Sat Mar 30, 2013 11:00 am

There are installation instructions in the documentation:
http://pythonhosted.org/oursql/install.html
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: No errors displayed but a blank screen instead

Postby NikosGr » Sat Mar 30, 2013 12:56 pm

I read id but ima somehow confused

is it ok to run these 2 commands?

python setup.py build_ext
python setup.py install
NikosGr
 
Posts: 48
Joined: Thu Mar 28, 2013 6:31 pm
Location: Thessaloniki

Re: No errors displayed but a blank screen instead

Postby stranac » Sat Mar 30, 2013 3:29 pm

Yes, that's one possible way to do it.

Might be better to just use pip, using:
Code: Select all
pip install oursql

Also, you might want to do it in a virtualenv.

Since oursql can be installed using pip, your host's support will probably be able to install it for you(at least that's what I think based on their message), in case you run into any problems.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Next

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], snippsat, W3C [Linkcheck] and 4 guests

cron