[error] [client 178.59.111.223] (2)No such file or directory: execof

F

Ferrous Cranus

Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 2:51:03 μ.μ. UTC+3, ο χÏήστης ishish έγÏαψε:
Am 28.08.2013 12:14, schrieb Ferrous Cranus:
Okey, continue trying and trying i came up with this:



if os.path.exists( path + page ) or os.path.exists( cgi_path + page

cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone()

with open("err.out", "a") as f:
f.write( repr(query), type(query) )
f.write( repr(escaped_args), type(escaped_args) )


But i cannot test it without looking at the error log which is
scrolling like hell and doesn't even quit with a ctrl+c

How will i manage to troubleshoot?
Please confirm the above is correct and is what you were propsoing i
shoudl test.



A simple way I always use if it comes to exception handling:



import sys

import traceback



# Exception Identification

def formatExceptionInfo(maxTBlevel=5):

cla, exc, trbk = sys.exc_info()

excName = cla.__name__

try:

excArgs = exc.__dict__["args"]

except KeyError:

excArgs = "<no args>"

excTb = traceback.format_tb(trbk, maxTBlevel)

return (excName, excArgs, excTb)



try:

# Your code

except:

print formatExceptionInfo()

(e-mail address removed) [~/www]# [Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] malformed header from script. Bad header=<class 'str'> 'index.html': metrites.py
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Error in sys.excepthook:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] ValueError: underlying buffer has been detached
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120]
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Original exception was:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] Traceback (mostrecent call last):
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] File "/home/nikos/public_html/cgi-bin/metrites.py", line 191, in <module>
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] if not data:
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] NameError: name'data' is not defined
[Wed Aug 28 12:02:53 2013] [error] [client 108.162.231.120] File does not exist: /home/nikos/public_html/500.shtml
 
S

Steven D'Aprano

Τη ΤÏίτη, 27 ΑυγοÏστου 2013 8:07:52 μ.μ. UTC+3, ο χÏήστης Steven
D'Aprano έγÏαψε:
Hint: you can use
"print(type(page), file=open('path/to/some/file', 'w'))"

to see the type of the variable 'page' without displaying it on your
website.

i tried to do what you said and iam receing this:

[Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120] Original
exception was: [Wed Aug 28 08:43:31 2013] [error] [client
108.162.231.120] Traceback (most recent call last): [Wed Aug 28 08:43:31
2013] [error] [client 108.162.231.120] File
"/home/nikos/public_html/cgi-bin/metrites.py", line 39, in <module> [Wed
Aug 28 08:43:31 2013] [error] [client 108.162.231.120] print(
type(page), file=open('../err.out', 'w') ) [Wed Aug 28 08:43:31 2013]
[error] [client 108.162.231.120] PermissionError: [Errno 13]
\\u0386\\u03c1\\u03bd\\u03b7\\u03c3\\u03b7
\\u03c0\\u03c1\\u03cc\\u03c3\\u03b2\\u03b1\\u03c3\\u03b7\\u03c2:
'../err.out' [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120]
Premature end of script headers: metrites.py

Then pick a different location, one where you have permission to write
files!

Honestly Nikos, I'm not trying to be rude, but if you cannot think of
this on your own after all this time we've been helping you, perhaps
programming is not the right vocation for you. Perhaps you need to
consider a change of career.

If you do decide to stay as a web developer, you need to start thinking:

* What is this error message telling me? ("Permission denied")

* How can I fix that? ("I need permission to read the file. Maybe try a
different file?")


Also many times when i try to view the error_log by

tail -F /usr/local/apache/logs/error_log &

i get realtime scrolling of other joomla webistes pho errors and i have
hard time trackign my own webistes erros.

is ther a work around for that?


That's an apache logging issue, not Python, and I don't know enough about
apache to do more than guess that there probably is a solution but I have
no idea what it is.
 
I

ishish

Well there you have it:

File "/home/nikos/public_html/cgi-bin/metrites.py", line 191, in
<module>
if not data:
NameError: name 'data' is not defined
 
F

Ferrous Cranus

Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 3:11:07 μ.μ. UTC+3, ο χÏήστης Steven D'Aprano έγÏαψε:
Τη ΤÏίτη, 27 ΑυγοÏστου 2013 8:07:52 μ.μ. UTC+3, οχÏήστης Steven
D'Aprano έγÏαψε:

Hint: you can use
"print(type(page), file=open('path/to/some/file', 'w'))"

to see the type of the variable 'page' without displaying it on your
website.




i tried to do what you said and iam receing this:
[Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120] Original
exception was: [Wed Aug 28 08:43:31 2013] [error] [client
108.162.231.120] Traceback (most recent call last): [Wed Aug 28 08:43:31
2013] [error] [client 108.162.231.120] File
"/home/nikos/public_html/cgi-bin/metrites.py", line 39, in <module> [Wed
Aug 28 08:43:31 2013] [error] [client 108.162.231.120] print(
type(page), file=open('../err.out', 'w') ) [Wed Aug 28 08:43:31 2013]
[error] [client 108.162.231.120] PermissionError: [Errno 13]
\\u0386\\u03c1\\u03bd\\u03b7\\u03c3\\u03b7
\\u03c0\\u03c1\\u03cc\\u03c3\\u03b2\\u03b1\\u03c3\\u03b7\\u03c2:

'../err.out' [Wed Aug 28 08:43:31 2013] [error] [client 108.162.231.120]
Premature end of script headers: metrites.py



Then pick a different location, one where you have permission to write

files!



Honestly Nikos, I'm not trying to be rude, but if you cannot think of

this on your own after all this time we've been helping you, perhaps

programming is not the right vocation for you. Perhaps you need to

consider a change of career.



If you do decide to stay as a web developer, you need to start thinking:



* What is this error message telling me? ("Permission denied")



* How can I fix that? ("I need permission to read the file. Maybe try a

different file?")






Also many times when i try to view the error_log by

tail -F /usr/local/apache/logs/error_log &

i get realtime scrolling of other joomla webistes pho errors and i have
hard time trackign my own webistes erros.

is ther a work around for that?





That's an apache logging issue, not Python, and I don't know enough about

apache to do more than guess that there probably is a solution but I have

no idea what it is.

As i have pointed out i as the owner of the accoutn have read and write perimssion bot at www/ and www/cgi-bin
i also chnage the filename and still cant write to the file.

if you as experts cannot help resolve this, how me as a newbiw can?
 
S

Steven D'Aprano

but i cannot see the error_log because of constant scrolling of error
output.

Then don't use "tail -F", use "less".

Or try "tail -s 60 -F" which will update only every 60 seconds.
 
F

Ferrous Cranus

Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 3:21:25 μ.μ. UTC+3, ο χÏήστης Steven D'Aprano έγÏαψε:
Then don't use "tail -F", use "less".



Or try "tail -s 60 -F" which will update only every 60 seconds.

Very nice idea, than k you steven. Less work withiut scrilling like hell liek tail -F did.

this is what i have now:


# Exception Identification
def formatExceptionInfo(maxTBlevel=5):
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
try:
excArgs = exc.__dict__["args"]
except KeyError:
excArgs = "<no args>"
excTb = traceback.format_tb(trbk, maxTBlevel)
return (excName, excArgs, excTb)

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone() #URL is unique, so should only be one
except:
print( formatExceptionInfo() )

i see no error on what it used ot be isnteait comain at the follwing line which is:

if not data:
#first time for page; primary key is automatic, hit is defaulted
cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page )
cID = cur.lastrowid #get the primary key value of the new record
else:
#found the page, save primary key and use it to issue hit UPDATE
cID = data[0]
cur.execute('''UPDATE counters SET hits = hits + 1 WHERE ID = %s''',cID )


i jst dont follow..... What ishsi proposed supposed to give us the error inthe query bit now it tells difefrent things.

shoudl i remove the function since it want any helopfull?
 
S

Steven D'Aprano

As i have pointed out i as the owner of the accoutn have read and write
perimssion bot at www/ and www/cgi-bin i also chnage the filename and
still cant write to the file.

If you type filenames as carelessly as you type requests for help, who
knows what file name you are actually trying to open?

Or to put it another way...

If yuo tpye filnaems as carlesl yas y outype reqets for help, woh knwos
wha tfile nmae oyu ar eactaly tying to oep n?


Nikos, my Greek is completely non-existent, and I admire you for learning
a second language. I know your English is good, because I have seen you
write fluent, excellent English. But if you can't be bothered to type
carefully and clearly when asking questions, then how can you expect
others to be bothered to read and respond to your questions?

if you as experts cannot help resolve this, how me as a newbiw can?

Just because your account has write permission to a location doesn't mean
that the script being run by the webserver has write permission. You need
to write to a location where the script has permission to write. First
you need to find out what account the script is being run under -- it may
be "apache", or possible "nobody", but I don't know. It shouldn't be
"root", and almost certainly isn't "nikos". I'm not an expert, but a few
seconds googling came up with a lot of useful looking hits. Google on
"what user does apache run as" and do your research.

This is off-topic though. This is not a "beginner's guide to apache"
forum, if you can't solve this problem yourself you'll have to take it
elsewhere.
 
F

Ferrous Cranus

Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 3:38:11 μ.μ. UTC+3, ο χÏήστης Steven D'Aprano έγÏαψε:
If you type filenames as carelessly as you type requests for help, who

knows what file name you are actually trying to open?



Or to put it another way...



If yuo tpye filnaems as carlesl yas y outype reqets for help, woh knwos

wha tfile nmae oyu ar eactaly tying to oep n?





Nikos, my Greek is completely non-existent, and I admire you for learning

a second language. I know your English is good, because I have seen you

write fluent, excellent English. But if you can't be bothered to type

carefully and clearly when asking questions, then how can you expect

others to be bothered to read and respond to your questions?








Just because your account has write permission to a location doesn't mean

that the script being run by the webserver has write permission. You need

to write to a location where the script has permission to write. First

you need to find out what account the script is being run under -- it may

be "apache", or possible "nobody", but I don't know. It shouldn't be

"root", and almost certainly isn't "nikos". I'm not an expert, but a few

seconds googling came up with a lot of useful looking hits. Google on

"what user does apache run as" and do your research.



This is off-topic though. This is not a "beginner's guide to apache"

forum, if you can't solve this problem yourself you'll have to take it

elsewhere.

Hi steven , sorry for the typos.

you are write my script is invoked by apache web server application which it runs under account 'nobody'

Here is proof of that:

(e-mail address removed) [~]# ps aux | grep Apache
nikos 8531 0.0 0.0 6372 680 pts/0 R+ 12:44 0:00 grep Apache
(e-mail address removed) [~]# ps aux | grep apache
root 1101 0.0 0.2 65576 4168 ? Ss 08:30 0:01 /usr/local/apache/bin/httpd -k start -DSSL
root 8448 0.0 0.1 65576 1700 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8449 0.0 0.2 65712 3228 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8450 0.0 0.2 65848 3348 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8451 0.0 0.2 65848 3360 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8452 0.0 0.2 65712 3340 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8453 0.0 0.2 65712 3260 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8467 0.0 0.1 65712 2356 ? S 12:43 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8468 0.0 0.1 65712 2344 ? S 12:43 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 8519 0.0 0.1 65712 2344 ? S 12:43 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nikos 8537 0.0 0.0 6372 684 pts/0 R+ 12:44 0:00 grep apache

My script were all workign in the previous VPS enviroment, the script is correct is just a few minor thing in the new VPS env that they need to be taken care of thus prohibit my script to run..

please don't give up helping me and tell me please what you want me to try.
tahnk you very much.
 
F

Ferrous Cranus

This si what iam tryign now since the function ishish proposed wont help me.


try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone() #URL is unique, so should only be one
except:
print( repr(e) )


[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Original exception was:
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Traceback (most recent call last):
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] File "/home/nikos/public_html/cgi-bin/metrites.py", line 174, in <module>
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] query = query % escaped_args
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] TypeError: unsupported operand type(s) for %: 'bytes' and 'str'
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] During handling of the above exception, another exception occurred:
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] Traceback (most recent call last):
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] File "/home/nikos/public_html/cgi-bin/metrites.py", line 177, in <module>
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print( repr(e) )
[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] NameError: name 'e' is not defined
 
U

Ulrich Eckhardt

Am 28.08.2013 13:55, schrieb Ferrous Cranus:
Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 2:32:44 μ.μ. UTC+3, ο χÏήστης Dave Angel έγÏαψε:
You really have no directory in which you have write permissions? If
so, perhaps you'd better solve that first.


of cours ei ahve write permissions. Here:

(e-mail address removed) [~]# ls -ld www/
drwxr-x--- 4 nikos nobody 4096 Jul 13 10:33 www//
(e-mail address removed) [~]# ls -ld www/cgi-bin/
drwxr-xr-x 2 nikos nikos 4096 Aug 28 10:41 www/cgi-bin//


whick make it a mysterya s to why
with open("../err.out", "a") as f:
fails to write the file.

....maybe it's because the server is not running as user nikos?

Uli
 
F

Ferrous Cranus

Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 4:38:02 μ.μ. UTC+3, ο χÏήστης Ulrich Eckhardt έγÏαψε:
Am 28.08.2013 13:55, schrieb Ferrous Cranus:
Τη ΤετάÏτη, 28 ΑυγοÏστου 2013 2:32:44 μ.μ. UTC+3, ο χÏήστης Dave Angel έγÏαψε:
You really have no directory in which you have write permissions? If
so, perhaps you'd better solve that first.
of cours ei ahve write permissions. Here:
(e-mail address removed) [~]# ls -ld www/
drwxr-x--- 4 nikos nobody 4096 Jul 13 10:33 www//
(e-mail address removed) [~]# ls -ld www/cgi-bin/
drwxr-xr-x 2 nikos nikos 4096 Aug 28 10:41 www/cgi-bin//


whick make it a mysterya s to why
with open("../err.out", "a") as f:
fails to write the file.



...maybe it's because the server is not running as user nikos?



Uli

Yes Uli, the script metrits.py is being invoked by Apache Web Server which in turn runs under user Nobody.
So, that mean that? user 'nobody' has no write permission to /home/nikos folder?
 
D

Dave Angel

no this is the general error log apache produces for all the server.

Is there a way to grep error logging info, pertainign only to my specific nikos account or my superhost.gr domain?

I now nothing about Apache logs, but how about grepping the client url ?

[client 108.162.231.120]

I still don't understand why you don't find or create a directory that
"nobody" has write access to, so you can be more flexible about what
information you log.

Or strip the problem down to a simple "page" that displays what print
emits in a simple form.
 
S

Steven D'Aprano

Normally I would have thought you would have a public_html or www
directory in your home folder that would be readable/writable to the web
server (and where you should write).

I expect that he does. But Nikos has tried writing to the Nikos home
directory, and to .. (the parent directory). I don't believe he has tried
writing to . (the current directory), or to /tmp. I'm not an expert, but
I expect that Apache should be able to write to one of those. And if not,
he has root on his system, he can simply create a writable directory and
write to that.

I expect that there are security implications of having a directories
writable to the webserver user, but temporarily creating one for a quick
debugging aid should be okay.
 
S

Steven D'Aprano

This si what iam tryign now since the function ishish proposed wont help
me.

I see that your apology for careless writing didn't last very long.

[...]
except:
print( repr(e) )

What is the value of "e" here, and where is it defined?

Let's look at the error in your log file:

[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print(
repr(e) ) [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
NameError: name 'e' is not defined


Did you bother to read the error before asking for help?

Variable 'e' is not defined. Perhaps you should define it?
 
S

Steven D'Aprano

At any rate, isn't
this stuff really something that the Web Server company should be
helping him with? Its their server, they know how it is configured, and
they can quickly look in his directories to figure out permissions
related issues.

Perhaps. But Nikos is reporting that his log file shows entries from all
the other websites on the server, which doesn't sound good to me. Surely
any decent, competent web server company would be able to ensure that
each customer sees only their own log entries?
 
C

Cameron Simpson

| Hi steven , sorry for the typos.
| you are write my script is invoked by apache web server application which it runs under account 'nobody'
[...]
| nobody 8449 0.0 0.2 65712 3228 ? S 12:42 0:00 /usr/local/apache/bin/httpd -k start -DSSL
[...]
| My script were all workign in the previous VPS enviroment, the script is correct is just a few minor thing in the new VPS env that they need to be taken care of thus prohibit my script to run..

Your previous VPS used "suexec" in the Apache. This one does not.

Cheers,
 
C

Cameron Simpson

| On Wed, 28 Aug 2013 01:46:01 -0700, Ferrous Cranus wrote:
| > Also many times when i try to view the error_log by
| > tail -F /usr/local/apache/logs/error_log &
| >
| > i get realtime scrolling of other joomla webistes pho errors and i have
| > hard time trackign my own webistes erros.
| >
| > is ther a work around for that?
|
| That's an apache logging issue, not Python, and I don't know enough about
| apache to do more than guess that there probably is a solution but I have
| no idea what it is.

Normal practice is to specify vhost specific log paths inside each
website's VirtualHost clause, thus splitting the log for each
website out into separate files.

http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost

Notice the ErrorLog directive inside the clause.

Cheers,
 
F

Ferrous Cranus

Τη Πέμπτη, 29 ΑυγοÏστου 2013 1:56:55 Ï€.μ. UTC+3, οχÏήστης Steven D'Aprano έγÏαψε:
This si what iam tryign now since the function ishish proposed wont help



I see that your apology for careless writing didn't last very long.



[...]
print( repr(e) )



What is the value of "e" here, and where is it defined?



Let's look at the error in your log file:




[Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120] print(
repr(e) ) [Wed Aug 28 13:08:27 2013] [error] [client 108.162.231.120]
NameError: name 'e' is not defined





Did you bother to read the error before asking for help?



Variable 'e' is not defined. Perhaps you should define it?

Yes indeed , that was a a syntax error by me:

try:
#find the needed counter for the page URL
if os.path.exists( path + page ) or os.path.exists( cgi_path + page ):
cur.execute('''SELECT ID FROM counters WHERE url = %s''', page )
data = cur.fetchone() #URL is unique, so should only be one
except Exception as e:
con.rollback() #something failed, rollback the entire transaction
print( repr(e) )

outputs:
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] File "/home/nikos/public_html/cgi-bin/metrites.py", line 206, in <module>
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] cur.execute('''SELECT hits FROM counters WHERE url = %s''', page )
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127] query = query % escaped_args

[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] File "/home/nikos/public_html/cgi-bin/metrites.py", line 206, in <module>
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] cur.execute('''SELECT hits FROM counters WHERE url = %s''', page )
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, inexecute
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] query = query % escaped_args
[Thu Aug 29 04:15:20 2013] [error] [client 141.101.98.154] TypeError: unsupported operand type(s) for %: 'bytes' and 'str'


Now at least 'superhost.gr' displays the error when one by browser http://superhost.gr
 
S

Steven D'Aprano

[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]
File "/home/nikos/public_html/cgi-bin/metrites.py", line 206, in
<module>
[Thu Aug 29 04:18:04 2013] [error] [client 108.162.229.127]
cur.execute('''SELECT hits FROM counters WHERE url = %s''', page ) [...]
TypeError: unsupported operand type(s) for %: 'bytes' and 'str'

Oh look, it's exactly the same error you started with. Congratulations,
you've made exactly no progress. As I asked you yesterday:

And what result does form.getvalue return?

What is its type? Is it a list, a tuple, a dict, a bytes object,
a float, a str object, something else?


Have you worked that out yet? If you can't work it out, you can guess,
and then test your guess:


page = form.getvalue('page')
if isinstance(page, list):
raise TypeError('guessed it was a list, it is a list')


If your guess is wrong, try another guess. Keep going until you work out
what type page is.

If you can't write to a data file, you can write to the error log:


page = form.getvalue('page')
raise TypeError('type of page is %r' % type(page))


Keep going until you find out what type of data the variable 'page' is
holding. Now read the error message again:

unsupported operand type(s) for %: 'bytes' and 'str'


Do you understand what that error means? Here is a hint: start a Python
interactive session, and try things for yourself:


steve@runes:~$ python3.3
Python 3.3.0rc3 (default, Sep 27 2012, 18:31:58)
[GCC 4.4.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
py>
py> 'string%s' % 'string'
'stringstring'
py>
py> b'bytes%s' % b'bytes'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes'


Do you see a pattern yet? What do you think will happen if you run this?


b'bytes%s' % 'string'


Try it and see for yourself.


Now look at the error message you are getting. Is it the same error
message? Do you think that perhaps it has the same cause? How do you
think you might solve this problem?

Hint: if you have a data item that is type A, and you need it to be type
B, you need to convert from A to B.
 

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
474,102
Messages
2,570,646
Members
47,254
Latest member
GayMilline

Latest Threads

Top