TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

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

Íßêïò Ãêñ33ê

Hello this is the following snippet that is causing me the error i mention in the Subject:


try:
cur.execute( '''SELECT url, hits FROM counters ORDER BY hits DESC''' )

data = cur.fetchall()
for row in data:
(url, hits) = row

print( "<tr><td><center><a href='http://superhost.gr/?show=log&page=%s'><font color=tomato size=5> %s </a></td>" ) % (url, url)
print( "<td><center><font color=cyan size=5> %s </a></td></tr>" ) % (hits)
except pymysql.ProgrammingError as e:
print( repr(e) )


you can slso see it at:

http://superhost.gr/?show=stats
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 26 ÌáÀïõ 2013 11:23:40 ð.ì. UTC+3, ï ÷ñÞóôçò Peter Otten Ýãñáøå:
Íßêïò Ãêñ33ê wrote:







Hint (Python 3):




a=%s, b=%s

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

a=1, b=2

Thank you very much Peter, so as it seems in Python 3.3.1 all substitutuonsmust be nested in print().
 
P

Peter Otten

Îίκος ΓκÏ33κ said:
Thank you very much Peter, so as it seems in Python 3.3.1 all
substitutuons must be nested in print().

Yes; in other words:

In Python 3 print() is a function.
 
Í

Íßêïò Ãêñ33ê

Perhaps cna you help a bit with tha too:
used to work in 2.6 but not with 3.3.1

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

import cgitb; cgitb.enable()
import cgi, os, sys
from http import cookies


# initialize cookie
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
nikos = cookie.get('nikos')


# if visitor cookie does exist
if nikos:
msg = "ÁÐÏ ÔÇÍ ÅÐÏÌÅÍÇ ÅÐÉÓÊÅØÇ ÓÏÕ ÈÁ ÓÅ ÕÐÏËÏÃÉÆÙ ÙÓ ÅÐÉÓÊÅÐÔÇ ÁÕÎÁÍÏÍÔÁÓ ÔÏÍ ÌÅÔÑÇÔÇ!"
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = -1 #this cookie will expire now
else:
msg = "ÁÐÏ ÄÙ ÊÁÉ ÓÔÏ ÅÎÇÓ ÄÅÍ ÓÅ ÅÉÄÁ, ÄÅÍ ÓÅ ÎÅÑÙ, ÄÅÍ ÓÅ ÁÊÏÕÓÁ! ÈÁ ÅÉÓÁÉ ÐËÅÏÍ Ï ÁÏÑÁÔÏÓÅÐÉÓÊÅÐÔÇÓ!!"
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = 60*60*24*30*12 #this cookie will expire ina year


print ( "Content-type: text/html; charset=utf-8\n" )
print( cookie, msg )
sys.exit(0)

ima getting internal server error.
 
C

Chris Angelico

Anyone seeign somethign wrong?

Yes. You're posting requests, then bumping the thread two hours later
as though you're entitled to a response quicker than that. Plus, the
problems you're seeing ought to be solved by the 2to3 utility. Use it.
Look at its output.

ChrisA
 
C

Carlos Nepomuceno

----------------------------------------
Date: Sun, 26 May 2013 06:00:51 -0700
Subject: Re: TypeError: unsupported operand type(s) for %: 'NoneType' and'tuple'
From: (e-mail address removed)
To: (e-mail address removed)

Anyone seeign somethign wrong?

I don't know any module 'http' in Python standard library.

Think you mean the 'http.cookies' module in Python 3.
 
N

nagia.retsina

Τη ΚυÏιακή, 26 ΜαÎου 2013 4:10:02 μ.μ. UTC+3, ο χÏήστης Chris Angelico έγÏαψε:
Yes. You're posting requests, then bumping the thread two hours later

as though you're entitled to a response quicker than that. Plus, the

problems you're seeing ought to be solved by the 2to3 utility. Use it.

Look at its output.



ChrisA

There is a tool that convert python 2.6.x code => python 3.x ?

Can you post a link to that toll plz?
 
C

Chris Angelico

Ôç ÊõñéáêÞ, 26 ÌáÀïõ 2013 4:10:02 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:

There is a tool that convert python 2.6.x code => python 3.x ?

Can you post a link to that toll plz?

You have its name. You have Google. You have a mailing list that is
getting tired of you not putting in any effort.

ChrisA
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 26 ÌáÀïõ 2013 6:24:55 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You have its name. You have Google. You have a mailing list that is

getting tired of you not putting in any effort.



ChrisA

Yes i saw it its name is 2to3 conversion but my code is already written in python3

i ahve written in line byu line from sctatrch ,much like pelatologio.py
which when i intreprtet in via cmd i get no errors.

i dont understand why iam receiving an internal server error for both in browser mdoe though.
 
Í

Íßêïò Ãêñ33ê

Here is the live error log coming form apacher when i request the webpage form browser:

==> /usr/local/apache/logs/error_log <==
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py

what is that suexec?
 
M

Mark Lawrence

You have its name. You have Google. You have a mailing list that is
getting tired of you not putting in any effort.

ChrisA

Not to mention double spaced google crap :(
 
M

Mark Lawrence

Here is the live error log coming form apacher when i request the webpage form browser:

==> /usr/local/apache/logs/error_log <==
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] suexec failure: could not open log file
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script headers: koukos.py

what is that suexec?

What has this got to do with Python?
 
Í

Íßêïò Ãêñ33ê

Ôç ÊõñéáêÞ, 26 ÌáÀïõ 2013 7:45:42 ì.ì. UTC+3, ï ÷ñÞóôçò Mark Lawrence Ýãñáøå:
What has this got to do with Python?

What do your questions have to do with a proper reply?
 

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

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top