An error when i switched from python v2.6.6 => v3.2.3

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

Íßêïò Ãêñ33ê

Today i switched to Python v3.2.3 on my remote web server at HostGator.
My cgi-script which it works at python v2.6.6 now produces theses errors:

--> -->
Traceback (most recent call last):
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute
r = self._query(query)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query
rowcount = self._do_query(q)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query
db.query(q)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "metrites.py", line 211, in <module>
cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) )
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute
self.errorhandler(self, exc, value)
File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass(errorvalue)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")

Even cursor.execute changes in python v3 ?

What are these errors about?
 
Í

Íßêïò Ãêñ33ê

Any ideas about the error please?

I can assure you all the statemnt are correct ebcause they work in python v2.6.6
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 11:06:27 ð.ì. UTC+2, ï ÷ñÞóôçò Íßêïò Ãêñ33ê Ýãñáøå:
Any ideas about the error please?



I can assure you all the statemnt are correct ebcause they work in pythonv2.6.6

can someone help this issue so my webiste will get back on working plz?
 
M

Michael Ross

Τη Πέμπτη, 7 ΜαÏτίου 2013 11:06:27 Ï€.μ. UTC+2, ο χÏήστης Îίκος ΓκÏ33κ
έγÏαψε:

can someone help this issue so my webiste will get back on working plz?

MySQLdb is python 2 only.
"MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently
supported. Python-3.0 will be supported in a future release."

Maybe try this one:
https://pypi.python.org/pypi/mysql-connector-python/1.0.9

Alternatively,
forget about subprocess.check_output,
call your metrites.py with os.system('python metrites.py some-temp-file')
and have it write its output to some-temp-file,
and read some-temp-file back into your template?
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 1:51:42 ì.ì. UTC+2, ï ÷ñÞóôçò Michael Ross Ýãñáøå:
MySQLdb is python 2 only.

"MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently

supported. Python-3.0 will be supported in a future release."



Maybe try this one:

https://pypi.python.org/pypi/mysql-connector-python/1.0.9



Alternatively,

forget about subprocess.check_output,

call your metrites.py with os.system('python metrites.py some-temp-file')

and have it write its output to some-temp-file,

and read some-temp-file back into your template?

Yes its better for me to give upon python3 for the moment being, because all that hassle was for makeing the subprocess command run.

Now i just followed your advice and tried:

elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

but produced error tells me that:

template undefined, htmldata = -1, counter = ' <center><a href="mailto:[email protected]"> ...st.gr/?show=stats"><font color=cyan> 0 </td>\n\t\t '

whay htmldata reeturn the value '-1' when os.sytem is executed?
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 1:51:42 ì.ì. UTC+2, ï ÷ñÞóôçò Michael Ross Ýãñáøå:
MySQLdb is python 2 only.

"MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently

supported. Python-3.0 will be supported in a future release."



Maybe try this one:

https://pypi.python.org/pypi/mysql-connector-python/1.0.9



Alternatively,

forget about subprocess.check_output,

call your metrites.py with os.system('python metrites.py some-temp-file')

and have it write its output to some-temp-file,

and read some-temp-file back into your template?

Yes its better for me to give upon python3 for the moment being, because all that hassle was for makeing the subprocess command run.

Now i just followed your advice and tried:

elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

but produced error tells me that:

template undefined, htmldata = -1, counter = ' <center><a href="mailto:[email protected]"> ...st.gr/?show=stats"><font color=cyan> 0 </td>\n\t\t '

whay htmldata reeturn the value '-1' when os.sytem is executed?
 
M

Michael Ross

Τη Πέμπτη, 7 ΜαÏτίου 2013 1:51:42 μ.μ. UTC+2, ο χÏήστης Michael Ross
έγÏαψε:

Yes its better for me to give upon python3 for the moment being, because
all that hassle was for makeing the subprocess command run.

Now i just followed your advice and tried:

elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py
/data/files/htmltemp')

but produced error tells me that:

template undefined, htmldata = -1, counter = ' <center><a
href="mailto:[email protected]"> ...st.gr/?show=stats"><font
color=cyan> 0 </td>\n\t\t '

whay htmldata reeturn the value '-1' when os.sytem is executed?

Because
"On Unix, the return value is the exit status of the process encoded in
the format specified for wait()."

It's in the documentation for os.system.
Which you should have read before asking here.

You may not intend it like that,
but if you ask any and all errors here, you effectively ask the list to
develop the software for you.

Seriously this is beyond the scope of volunteer help for a commercial site.
I'm bailing out.
 
Í

Íßêïò Ãêñ33ê

Please tell me at least if i ahve any syntax error in this line:

htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

please man its essential for my website to work otherwise 3 scripts i wrotewould not be able to produce proper html output that then i need to appenda string after them. her si what i want to do:

if htmlpage.endswith('.html'):
f = open( "/home/nikos/www/" + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')


counter = ''' <center><a href="mailto:[email protected]"> <img src="/data/images/mail.png"> </a>
<center><table border=2 cellpadding=2 bgcolor=black>
<td><font color=lime>Áñéèìüò Åðéóêåðôþí</td>
<td><a href="http://superhost.gr/?show=stats"><font color=cyan> %d </td>
''' % data[0]


template = htmldata + counter
print( template )

======================

Please just that i like to do it myself ut i cant, i wont ask anyhting else..
 
Í

Íßêïò Ãêñ33ê

Please tell me at least if i ahve any syntax error in this line:

htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

please man its essential for my website to work otherwise 3 scripts i wrotewould not be able to produce proper html output that then i need to appenda string after them. her si what i want to do:

if htmlpage.endswith('.html'):
f = open( "/home/nikos/www/" + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')


counter = ''' <center><a href="mailto:[email protected]"> <img src="/data/images/mail.png"> </a>
<center><table border=2 cellpadding=2 bgcolor=black>
<td><font color=lime>Áñéèìüò Åðéóêåðôþí</td>
<td><a href="http://superhost.gr/?show=stats"><font color=cyan> %d </td>
''' % data[0]


template = htmldata + counter
print( template )

======================

Please just that i like to do it myself ut i cant, i wont ask anyhting else..
 
C

Chris Angelico

Please tell me at least if i ahve any syntax error in this line:

htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp')

please man its essential for my website to work otherwise 3 scripts i wrote would not be able to produce proper html output

Yes, there is. The variable name at the beginning is wrong. To
understand why, look at the documentation for os.system().

If it's essential for your web site, why not pay someone to do the work foryou?

You want free support AND you're not willing to put effort into your
questions. That's a bad combination. The sloppiness of your writing,
coupled with a clear lack of preliminary research (eg checking the
docs), suggests that you do not value the end result; you expect
someone else to do everything, to wave a magic wand and voila, your
web site works. That isn't how the world works.

Quoting from http://www.catb.org/esr/faqs/smart-questions.html
== Before you ask ==
Prepare your question. Think it through. Hasty-sounding questions get
hasty answers, or none at all. The more you do to demonstrate that having
put thought and effort into solving your problem before seeking help, the
more likely you are to actually get help. ....
== Write in clear, grammatical, correctly-spelled language ==
... If you can't be bothered to do that, we can't be bothered to pay attention.
Spend the extra effort to polish your language. It doesn't have to be stiff or
formal - in fact, hacker culture values informal, slangy and humorous
language used with precision. But it has to be precise; there has to be
some indication that you're thinking and paying attention.
... if you write like a semi-literate boob you will very likely be ignored.

ChrisA
 
Í

Íßêïò Ãêñ33ê

But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running

all the above fail:

htmldata = os.system("python metrites.py '/data/files/htmltemp'")

How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do:

template = htmldata + counter

os.system is very vague while i need specific help with this.
if you provide me a link that describes my case of things i';; for sure read it.
 
Í

Íßêïò Ãêñ33ê

But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running

all the above fail:

htmldata = os.system("python metrites.py '/data/files/htmltemp'")

How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do:

template = htmldata + counter

os.system is very vague while i need specific help with this.
if you provide me a link that describes my case of things i';; for sure read it.
 
C

Chris Angelico

But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running

all the above fail:

htmldata = os.system("python metrites.py '/data/files/htmltemp'")

How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do:

template = htmldata + counter

os.system is very vague while i need specific help with this.
if you provide me a link that describes my case of things i';; for sure read it.

You are panicking about specific problems. Take a deep breath, take a
step back, and look at what's going on. If you've really been trying
for three days to make this work, it won't cost you much more to spend
three minutes polishing your email before you send it... or those same
three minutes reading the docs and finding what you want.

ChrisA
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 4:01:13 ì.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You are panicking about specific problems. Take a deep breath, take a

step back, and look at what's going on. If you've really been trying

for three days to make this work, it won't cost you much more to spend

three minutes polishing your email before you send it... or those same

three minutes reading the docs and finding what you want.

Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it....

I think its an OS issue and not statment issue.

iam starting to hink that maybe

python metritis.py > /data/files/htmltemp

might work. i will try this now as we speak.lets hope for God;s sake it will work!
 
Í

Íßêïò Ãêñ33ê

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 4:01:13 ì.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You are panicking about specific problems. Take a deep breath, take a

step back, and look at what's going on. If you've really been trying

for three days to make this work, it won't cost you much more to spend

three minutes polishing your email before you send it... or those same

three minutes reading the docs and finding what you want.

Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it....

I think its an OS issue and not statment issue.

iam starting to hink that maybe

python metritis.py > /data/files/htmltemp

might work. i will try this now as we speak.lets hope for God;s sake it will work!
 
Í

Íßêïò Ãêñ33ê

I made some progress!!! Now the htmldata's value its not -1 but 256!!!

look the error after trying this:
htmldata = os.system("python metrites.py > '/data/private/htmltemp'")

====================
template undefined, htmldata = 256, counter = ' <center><a href="mailto:[email protected]"> ...st.gr/?show=stats"><font color=cyan> 0 </td>\n\t\t '
<type 'exceptions.TypeError'>: unsupported operand type(s) for +: 'int' and 'str'
args = ("unsupported operand type(s) for +: 'int' and 'str'",)
message = "unsupported operand type(s) for +: 'int' and 'str'"
 
Í

Íßêïò Ãêñ33ê

I made some progress!!! Now the htmldata's value its not -1 but 256!!!

look the error after trying this:
htmldata = os.system("python metrites.py > '/data/private/htmltemp'")

====================
template undefined, htmldata = 256, counter = ' <center><a href="mailto:[email protected]"> ...st.gr/?show=stats"><font color=cyan> 0 </td>\n\t\t '
<type 'exceptions.TypeError'>: unsupported operand type(s) for +: 'int' and 'str'
args = ("unsupported operand type(s) for +: 'int' and 'str'",)
message = "unsupported operand type(s) for +: 'int' and 'str'"
 
C

Chris Angelico

Ôç ÐÝìðôç, 7 Ìáñôßïõ 2013 4:01:13 ì.ì. UTC+2, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:


Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it....
http://www.google.com/

I think its an OS issue and not statment issue.

I think it's a pebkac issue.
iam starting to hink that maybe

python metritis.py > /data/files/htmltemp

might work. i will try this now as we speak.lets hope for God;s sake it will work!

Tip: Next time, try it first, THEN post. This is not IRC. You don't
need to tell us that you're trying, and that you're panicking still
further.

ChrisA
 
C

Chris Angelico

I made some progress!!! Now the htmldata's value its not -1 but 256!!!

look the error after trying this:
htmldata = os.system("python metrites.py > '/data/private/htmltemp'")

Go check the docs for os.system() and understand why 'htmldata' is the
wrong name for its return value.

ChrisA
 
Í

Íßêïò Ãêñ33ê

Docs doesn't explain that i just take looked at http://docs.python.org/2/library/os.html#os.system

I see that the return value of os.system its an indicator to as if the command inside os.system() returned successfully.

So i guess ill be needing somethign like this:

htmltemp = '/home/nikos/www/data/private/htmltemp'

if htmlpage.endswith('.html'):
f = open( "/home/nikos/www/" + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
os.system( 'python metrites.py > %s' ) % htmltemp
f = open( htmltemp )
htmldata = f.read()

template = htmldata + counter
==============

which i just tried and now iam receiving this:

<type 'exceptions.TypeError'>: unsupported operand type(s) for %: 'int' and 'str'

I'am very close to the solution now i cna feel it but please help a bit!
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top