Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.036 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'corresponds': 0.09; 'query,': 0.09; '(%s,': 0.16; 'subject:hyphen': 0.16; 'cc:addr :python-list': 0.16; 'syntax': 0.16; 'wrote:': 0.18; 'subject:not': 0.19; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'received:209.85.220': 0.25; 'cc:2**0': 0.26; 'noticed': 0.26; 'all,': 0.27; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'server': 0.30; 'sun,': 0.30; 'chris': 0.30; 'error': 0.30; 'version': 0.32; 'values': 0.32; 'go.': 0.32; "can't": 0.33; '"we': 0.34; 'something': 0.35; '"you': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'received:209': 0.39; 'raw': 0.40; 'your': 0.61; 'below:': 0.80; '("we': 0.84; 'injection': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=CcSm5INzDaRKd3IGOnksvLop7cF6XY8Lm1G6uu80elE=; b=D2L66u4dDMb0RHwtCqYTPNRCMrFaYIjSNP6yUIXETwMH8+npyLVFj/zArVIfZnekES 8KmWDLzwF30NBz0BrtdZWx2rWePYftc4L0yJU1Q2LYQrE+QutsRT0gB1YPCSD3VjteO8 2wNlgRARBmle670pMxcHZq0PFDqfDF4gZMFpc= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Sun, 5 Feb 2012 14:46:36 -0800 X-Google-Sender-Auth: 1A0HHaMSivEtHN9GqbW3VTS73no Subject: Re: MySQLdb not allowing hyphen From: Chris Rebert To: Emeka Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328481998 news.xs4all.nl 6945 [2001:888:2000:d::a6]:56524 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19879 On Sun, Feb 5, 2012 at 2:41 PM, Emeka wrote: > > Hello All, > > I noticed that=C2=A0MySQLdb not allowing hyphen may be way to prevent inj= ection > attack. > I have something like below: > > "insert into reviews(message, title)values('%s', '%s')" %( "We don't know > where to go","We can't wait till morrow"=C2=A0) > > ProgrammingError(1064, "You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right syntax= to > use near 't know where to go. > > How do I work around this error? Don't use raw SQL strings in the first place. Use a proper parameterized query, e.g.: cursor.execute("insert into reviews(message, title) values (%s, %s)", ("We don't know where to go", "We can't wait till morrow")) Cheers, Chris