cannot concatenate 'str' and 'list' objects

  • Thread starter Íéêüëáïò Êïýñáò
  • Start date
Í

Íéêüëáïò Êïýñáò

I swicthed back my code to: f = open( '../' + page )

and http://superhost.gr works which means that line gets parsed correctly.

Only when i post data to the text area boxes iam getting the error:

cannot concatenate 'str' and 'list' objects

how is this possible to work before and NOT work when i enter data to the page for storing to the database?
 
Í

Íéêüëáïò Êïýñáò

You are right but iam a new python learner and i created this logging system script as a poject to better learn the lalguage itself.

I can always use google analytics for serious visitor logging.

Apart from that i enjoy reading my logs by typing:

http://superhost.gr/?show=log

:)
 
C

Chris Angelico

I swicthed back my code to: f = open( '../' + page )

and http://superhost.gr works which means that line gets parsed correctly..

Only when i post data to the text area boxes iam getting the error:

cannot concatenate 'str' and 'list' objects

how is this possible to work before and NOT work when i enter data to thepage for storing to the database?

Okay. Putting everything together, I think I can see what's going on.

You have a rewrite rule that's changing http://superhost.gr/ into a
request that, if my hand-parsing of Apache directives is working,
looks like this:
http://superhost.gr/cgi-bin/counter.py?page=index.html

That page doesn't quite work, as the browser goes looking for images
and CSS in cgi-bin instead of the root, but that's pretty much what's
going on. (I had to guess that it was index.html, as that part is
implicit in the original URL.)

You then have a request with a GET variable named 'page', and also a
POST variable named 'page', courtesy of the hidden form variable. This
would be why you're getting a list instead of a string.

Is the hidden form field completely redundant? If so, just remove it.
If you need that information for some other reason (eg you want to
record which page the user came from), then rename one or other of
them.

I would recommend a naming convention whereby you keep "internal
stuff" away from your main site. For instance, change your rewrite
rule to create a form field called _page and have counter.py look for
that. Or better still, don't use the query string for that at all, if
you can (I can't remember off-hand what a rewrite rule can set, but I
think you can carry extra information around in other ways).
Currently, your site can be broken by adding a query string to the
URL:

http://superhost.gr/?page=hahahaha

As a general rule, a web site should not get confused by the presence
of an unexpected form field. It's not good for someone to be able to
break your page like this!

It appears that part of the problem is that your getvalue() function
has three possibilities, similar to the issue I had a while ago with a
similar PHP function. Readers of CS Lewis may recognize what I'm
saying... Either she is lying, and there is no array at all; or she is
mad - a single item as a scalar instead of an array; or she is telling
the truth, and we have an array just like we need.

ChrisA
 
C

Chris Angelico

You are right but iam a new python learner and i created this logging system script as a poject to better learn the lalguage itself.

I can always use google analytics for serious visitor logging.

Apart from that i enjoy reading my logs by typing:

http://superhost.gr/?show=log

Yes, and I'm sure random visitors will enjoy reading them too, with no
authentication required. You really shouldn't make all your visitors'
IP addresses and usage stats public. Also, you may want to consider
recording IP addresses for the "reverse dns lookup failed" entries, as
there'll be a lot of them :)

ChrisA
 
Í

Íéêüëáïò Êïýñáò

I'am not sure what to do and i didnt quite understand what the problem is.

Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes?
 
Í

Íéêüëáïò Êïýñáò

I'am not sure what to do and i didnt quite understand what the problem is.

Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes?
 
C

Chris Gonnerman

I moved to HostGaot because i heard there were the best in the hosting
business.....
They are pretty good. However, you have to understand the site layout
to do CGI safely.

So long as your script are .cgi, putting them in ~/public_html is fine.
If you need to deploy .py files, you need to put them in a different
folder outside ~/public_html, for example ~/lib or ~/python, then in
your CGI scripts you need to add that to the path.

For example:

#!/usr/bin/python

import sys
sys.path.append("../python")

import MyModule, MyPackage.OtherModule

This is more or less how all my CGI scripts on HostGator are done.

-- Chris.
 
C

Chris Gonnerman

I swicthed back my code to: f = open( '../' + page )

and http://superhost.gr works which means that line gets parsed correctly.

Only when i post data to the text area boxes iam getting the error:

cannot concatenate 'str' and 'list' objects

how is this possible to work before and NOT work when i enter data to the page for storing to the database?
You really need to add some print-type diagnostics to your script
temporarily, just to see what you are actually getting for parameters.
For example, put this:

print "Content-type: text/plain\n"

near the top so you can get a source printout, then add

print `page`

just before you attempt your open() call so you can see what the exact
Python representation of page is. Do similarly for other problems in
your code. Don't leave such an "instrumented" copy of your CGI script on
your site for very long and you should be safe.

Also, consider using the built-in cgi traceback feature in your scripts,
at least while you are debugging them (though you probably want to
remove the traceback after you are "in production").

-- Chris.
 
C

Chris Angelico

I'am not sure what to do and i didnt quite understand what the problem is..

Can you please tell me what parts need fixe so for the users to be able to leave remakrs in he text area boxes?

Your question demonstrates a more fundamental issue here, which I'll
look at before answering what you actually asked.

You're looking to fix your immediate problem and keep moving, without
seeking to understand what's actually going on. This means you will,
in all probability, bounce from crisis to crisis without ever fixing
anything deep underneath; maybe your next issue will be an SQL
injection problem, so you'll fiddle with all your database queries,
but never connect that to this.

The stated purpose of this project is to learn. Learn as much as you
possibly can, then, and get a deep understanding of the underlying
structure. Use Firebug or the Chrome F12 debug information or
something of the sort to watch the requests going back and forth. Leaf
through the Apache logs. Print a whole lot of information to the page
or to an offline log. And remember, anything you can do, someone else
can do just as easily, so with any private information, make sure it's
at least protected by a username and password.

Now, to answer your question. Actually, I already answered it in my
previous post. First, decide whether or not you need the 'page' form
field. Either it's redundant or it's necessary.

1) If it's redundant: Easy. Delete it. Your page will begin working again.
2) If it's necessary: Either rename it, or rename the form field you
use in your rewrite rule.

But spare a thought for the way your script can so easily be broken by
simply appending "?page=" to any URL. That's not good, especially
given how much internal information gets dumped to the page.

ChrisA
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:25:15 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
First, decide whether or not you need the 'page' form
field. Either it's redundant or it's necessary.



1) If it's redundant: Easy. Delete it. Your page will begin working again..

2) If it's necessary: Either rename it, or rename the form field you

use in your rewrite rule.


The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files)

I still do not see why you say that it might be redundant.

But spare a thought for the way your script can so easily be broken by

simply appending "?page=" to any URL. That's not good, especially

given how much internal information gets dumped to the page.

I tried it, it doesnt load any webistes that way.

i.e. http://superhost.gr?page='www.google.gr' fails to load.
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:25:15 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
First, decide whether or not you need the 'page' form
field. Either it's redundant or it's necessary.



1) If it's redundant: Easy. Delete it. Your page will begin working again..

2) If it's necessary: Either rename it, or rename the form field you

use in your rewrite rule.


The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files)

I still do not see why you say that it might be redundant.

But spare a thought for the way your script can so easily be broken by

simply appending "?page=" to any URL. That's not good, especially

given how much internal information gets dumped to the page.

I tried it, it doesnt load any webistes that way.

i.e. http://superhost.gr?page='www.google.gr' fails to load.
 
C

Chris Angelico

The 'page' form field is of couse neccessary because how else the python counter.py script would know which html file triggered it so to present it and do its log thing?(i intend to create a few html files)

I still do not see why you say that it might be redundant.

You create one 'page' value in the form, and another one in the RewriteRule..

ChrisA
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:56:31 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You create one 'page' value in the form, and another one in the RewriteRule.

i changes the .htaccess to

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]

but now my webpage presents the error right away.
I dont understand.
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:56:31 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You create one 'page' value in the form, and another one in the RewriteRule.

i changes the .htaccess to

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]

but now my webpage presents the error right away.
I dont understand.
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 8:22:39 ì.ì. UTC+3, ï ÷ñÞóôçò Íéêüëáïò Êïýñáò Ýãñáøå:
Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:56:31 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You create one 'page' value in the form, and another one in the RewriteRule.



i changes the .htaccess to



RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f

RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]



but now my webpage presents the error right away.

I dont understand.

aahhh! alo it needed change to

page = form.getvalue('htmlpage')

now its working! at last!

but can you please tell me what was wrong?

Tha names of the variables was the same both in counter.py and the .htaccess

But why was that confusing?
 
Í

Íéêüëáïò Êïýñáò

Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 8:22:39 ì.ì. UTC+3, ï ÷ñÞóôçò Íéêüëáïò Êïýñáò Ýãñáøå:
Ôç ÓÜââáôï, 15 Óåðôåìâñßïõ 2012 7:56:31 ì.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå:
You create one 'page' value in the form, and another one in the RewriteRule.



i changes the .htaccess to



RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f

RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]



but now my webpage presents the error right away.

I dont understand.

aahhh! alo it needed change to

page = form.getvalue('htmlpage')

now its working! at last!

but can you please tell me what was wrong?

Tha names of the variables was the same both in counter.py and the .htaccess

But why was that confusing?
 
C

Chris Angelico

aahhh! alo it needed change to

page = form.getvalue('htmlpage')

now its working! at last!

but can you please tell me what was wrong?

Tha names of the variables was the same both in counter.py and the .htaccess

But why was that confusing?

This is what I'm trying to explain. You need to get to know what's
really happening; what is the rewrite rule doing? I could walk you
through it, there's nothing magical about it, but you really need to
study it for yourself so that you actually understand what's going on.

You've now solved your immediate issue, so you'll probably be tempted
to ignore everything else and move on. And if you're on time pressure,
that's perhaps the right decision. (Five hours and you have a fully
working solution. Not bad for free assistance!) But you still have the
page-breaking issue:

http://superhost.gr/?htmlpage=broken

And there's still the question of whether or not the hidden form field
is needed. I suspect it probably isn't. But these are questions for
you to work out the answers to yourself.

I get an impression from your posts that you're working shallowly, and
probably in some haste. Your posts are somewhat sloppy in spelling and
capitalization; I understand that English probably isn't your first
language, but careful writing is not difficult, and you'll spare
yourself the reputation of sloppy work and sloppy thinking.

It takes time to truly master anything. Whether it's riding a bicycle,
solving Rubik's Cube, or building a web site, you'll need to put in
some hours before you can truly expect to comprehend your work. Trying
to short-cut that usually results in problems down the road. Put in
the time, gain the skill, and you'll reap the rewards!

ChrisA
 
Í

Íéêüëáïò Êïýñáò

What hidden form value?

you mean page variable does not needed? please clarify.

Also i dont know what to do if someone enters a false entry as content for htmlpage.
 
Í

Íéêüëáïò Êïýñáò

What hidden form value?

you mean page variable does not needed? please clarify.

Also i dont know what to do if someone enters a false entry as content for htmlpage.
 
C

Chris Angelico

What hidden form value?

you mean page variable does not needed? please clarify.

Also i dont know what to do if someone enters a false entry as content for htmlpage.

You have this:
<input type="hidden" name="page" value="index.html">

What is that for? Is it needed?

ChrisA
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top