Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'anyway.': 0.04; '%s"': 0.07; 'host,': 0.07; 'rewrite': 0.07; "subject:' ": 0.07; 'try:': 0.07; 'scripts': 0.09; 'mess': 0.09; 'scripts,': 0.09; 'sep': 0.09; 'charset:iso-8859-7': 0.15; '"error': 0.16; '%d:': 0.16; '%s,': 0.16; '(code': 0.16; 'all...': 0.16; 'available...': 0.16; 'developing,': 0.16; 'emit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guilty': 0.16; 'hits': 0.16; 'row': 0.16; 'roy': 0.16; 'scripts.': 0.16; 'sorts': 0.16; 'statistics.': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'appears': 0.18; 'code,': 0.18; 'code.': 0.20; 'parse': 0.22; "i'd": 0.22; 'errors': 0.23; 'flexibility': 0.23; 'insert': 0.23; "i've": 0.23; 'host': 0.24; 'header:In- Reply-To:1': 0.25; 'appear': 0.26; 'am,': 0.27; 'coding': 0.27; 'pages,': 0.27; 'separate': 0.27; 'errors.': 0.27; 'replace': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'hosting': 0.28; 'record': 0.28; 'cgi': 0.29; 'loads': 0.29; "they'll": 0.29; 'usually': 0.30; 'primary': 0.30; 'stuff': 0.30; 'code': 0.31; 'file': 0.32; 'switch': 0.32; 'print': 0.32; 'dates': 0.33; 'to:addr:python-list': 0.33; 'monitor': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'fail': 0.35; 'said,': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'except': 0.36; 'but': 0.36; "didn't": 0.36; "i'll": 0.36; 'should': 0.36; 'execute': 0.37; 'two': 0.37; 'maintaining': 0.37; 'previous': 0.37; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'easier': 0.38; 'fact': 0.38; 'some': 0.38; 'things': 0.38; 'sure': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'company': 0.60; 'most': 0.61; "you'll": 0.62; 'back': 0.62; 'more': 0.63; 'agent': 0.64; 'making': 0.64; 'to,': 0.65; 'date,': 0.65; 'pin': 0.65; 'risk': 0.66; 'url:cgi-bin': 0.66; 'today': 0.67; 'consequences': 0.71; 'race': 0.71; 'day': 0.73; 'agent,': 0.84; 'insecure': 0.84; "site's": 0.84; 'wheel': 0.84; 'working,': 0.84; 'severe': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=LkQ5Hy91HAw8P+38cb6Hp1xI+dIpgEYeh4K0631iDrI=; b=nfqvTDGevjODxO/Hz/Rnm2u7YdRFoRfRwaV7Cx9LOL50ERi90plqv1ua/8vjCpd6c9 DFtGQJCDCZVxcBC0YleAoQoQFfKRF36thByGYuhiB8+Kw1qJol8uewDLCOqGKNk5aJ1l Cob36+/FKWnjiHZvTcyN0Fan5FtkfCSU8JvIGq7wB/l1BQ93yXgqetx8CrICVRD0Q0ED SppiuGNd5df2elcx4nIYj5GXrMsuql9EQZpj86KiZKuxUb+q2hhUTX2LjLCoSGq7SHle FOY8ZRCYT3PEYk35JtOntT2z65CDATVtRPXS+1qTajLK0iR8NlqbZUIwvqy+15FtNLAL 7i4Q== MIME-Version: 1.0 In-Reply-To: <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com> References: <071ad036-77ca-42d3-b68d-0dd3e3fac43e@googlegroups.com> <181f1ff8-0f25-48d3-9265-1c2afef7f95b@googlegroups.com> Date: Sun, 16 Sep 2012 01:23:09 +1000 Subject: Re: cannot concatenate 'str' and 'list' objects From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347722592 news.xs4all.nl 6976 [2001:888:2000:d::a6]:34748 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29242 On Sun, Sep 16, 2012 at 1:06 AM, =CD=E9=EA=FC=EB=E1=EF=F2 =CA=EF=FD=F1=E1= =F2 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 =3D hits + 1, agent =3D %s, date =3D %s WHERE pin =3D %s AND host =3D %s''', (agent, date, pin, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) =09 # insert new visitor record if above update did not affect a row if cursor.rowcount =3D=3D 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