Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > cannot concatenate 'str' and 'list' objects

Reply
Thread Tools

cannot concatenate 'str' and 'list' objects

 
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      09-15-2012
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?
 
Reply With Quote
 
 
 
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      09-15-2012
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


 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      09-15-2012
On Sun, Sep 16, 2012 at 1:23 AM, Νικόλαος Κούρας <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      09-15-2012
On Sun, Sep 16, 2012 at 1:33 AM, Νικόλαος Κούρας <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      09-15-2012
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?
 
Reply With Quote
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      09-15-2012
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?
 
Reply With Quote
 
Chris Gonnerman
Guest
Posts: n/a
 
      09-15-2012
> 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.
 
Reply With Quote
 
Chris Gonnerman
Guest
Posts: n/a
 
      09-15-2012
On 09/15/2012 10:23 AM, ΞΞΉΞΊΟŒΞ»Ξ±ΞΏΟ‚ ΞšΞΏΟΟΞ±Ο‚ wrote:
> 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.
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      09-15-2012
On Sun, Sep 16, 2012 at 2:04 AM, Νικόλαος Κούρας <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
Νικόλαος Κούρας
Guest
Posts: n/a
 
      09-15-2012
Τη Σάββατο, 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate/De-Concatenate Carlos VHDL 10 10-24-2012 01:04 PM
concatenate file-like objects -> file-like object kgk Python 1 07-11-2007 06:17 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
TypeError: cannot concatenate 'str' and 'NoneType' objects thompson.marisa@gmail.com Python 9 12-20-2006 08:26 PM
Concatenate datalist variables with javascript and html Luis Esteban Valencia ASP .Net 0 01-20-2005 01:57 PM



Advertisments