Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29242

Re: cannot concatenate 'str' and 'list' objects

References <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com>
Date 2012-09-16 01:23 +1000
Subject Re: cannot concatenate 'str' and 'list' objects
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.756.1347722592.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Sep 16, 2012 at 1:06 AM, Νικόλαος Κούρας <nikos.gr33k@gmail.com> wrote:
> Previous webhost has the same flaw as well, look:
>
> http://www.errorweb.gr/~nikos/cgi-bin/
>
> giving away all my scripts.
>
> Webhost misconfiguration in both hosts!

And when I look at the scripts, I see things that do not fill me with
confidence. You appear to be reinventing the wheel, and making it
hexagonal in the process. That's not to say you shouldn't tinker with
wheel design now and then, but as Roy said, the consequences get quite
severe once you're hosting a web site to the world.

I've been guilty of the same sorts of issues myself. I was poking at
some old code today (code that dates back a few years to when I was
new to PHP and didn't know of any other way to make a dynamic web site
other than CGI) and found some pretty ridiculous coding bloopers.
Stuff that didn't stop the site's primary functionality from working,
but it sure isn't what I'd call good code. Some day I'll rewrite it
all... some day I'll have time available... anyway.

Your counter.py appears to be doing what most people do after the fact
with log-file analysis. It's usually a lot better to simply parse
Apache's log files to find out how many people view your pages, rather
than maintaining the statistics. This has a race condition in it:

	# update existing visitor record if same pin and same host found
	try:
		cursor.execute( '''UPDATE visitors SET hits = hits + 1, agent = %s,
date = %s WHERE pin = %s AND host = %s''', (agent, date, pin, host))
	except MySQLdb.Error, e:
		print ( "Error %d: %s" % (e.args[0], e.args[1]) )
	
	# insert new visitor record if above update did not affect a row
	if cursor.rowcount == 0:
		cursor.execute( '''INSERT INTO visitors(pin, host, hits, agent,
date) VALUES(%s, %s, %s, %s, %s)''', (pin, host, 1, agent, date) )


If two page loads simultaneously execute this code, they'll both fail
to update, and then both attempt to insert.

Also, it's extremely insecure to simply print your database errors.
Emit them to a separate log file that only you have access to, and
monitor that log while you're developing. Once you're done developing,
switch to an alert system if you can, because SQL errors should never
occur (obviously don't alert if there are specific errors that you
intend to cause and catch).

See if you can replace the whole mess of CGI scripts with flat HTML
files and AWStats. You'll have much more flexibility in hosting
company choice, less risk of security breaches, and much MUCH easier
management.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 05:22 -0700
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 05:26 -0700
  Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-15 22:33 +1000
    Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 06:28 -0700
      Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-15 23:38 +1000
        Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 06:53 -0700
          Re: cannot concatenate 'str' and 'list' objects Peter Otten <__peter__@web.de> - 2012-09-15 16:29 +0200
            Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 07:51 -0700
              Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 00:55 +1000
            Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 07:51 -0700
        Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 06:53 -0700
          Re: cannot concatenate 'str' and 'list' objects Roy Smith <roy@panix.com> - 2012-09-15 10:21 -0400
            Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 07:44 -0700
              Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 00:49 +1000
              Re: cannot concatenate 'str' and 'list' objects Roy Smith <roy@panix.com> - 2012-09-15 11:01 -0400
                Re: cannot concatenate 'str' and 'list' objects Chris Gonnerman <chris@gonnerman.org> - 2012-09-15 11:09 -0500
    Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 06:28 -0700
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 07:56 -0700
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 08:01 -0700
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 08:06 -0700
    Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 01:23 +1000
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 08:23 -0700
    Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 01:44 +1000
      Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 09:04 -0700
        Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 02:25 +1000
          Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 09:53 -0700
            Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 02:56 +1000
              Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:22 -0700
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:26 -0700
                Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 03:42 +1000
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:59 -0700
                Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 04:02 +1000
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 11:10 -0700
                Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 09:11 +1000
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 11:10 -0700
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:59 -0700
                Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:26 -0700
              Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 10:22 -0700
          Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 09:53 -0700
      Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 09:04 -0700
    Re: cannot concatenate 'str' and 'list' objects Chris Gonnerman <chris@gonnerman.org> - 2012-09-15 11:13 -0500
  Re: cannot concatenate 'str' and 'list' objects Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2012-09-15 08:33 -0700
    Re: cannot concatenate 'str' and 'list' objects Chris Angelico <rosuav@gmail.com> - 2012-09-16 01:46 +1000

csiph-web