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


Groups > comp.lang.python > #61373

Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1")

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <daniel@daniel-watkins.co.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; 'causing': 0.04; 'resulting': 0.04; 'syntax': 0.04; 'insert': 0.05; '[0]': 0.09; 'dan': 0.09; 'from:addr:daniel': 0.09; 'subject:version': 0.09; 'cc:addr:python-list': 0.11; 'corresponds': 0.16; 'doing,': 0.16; 'subject: \n ': 0.16; 'wrote:': 0.18; 'library': 0.18; 'passing': 0.19; 'meant': 0.20; 'handles': 0.22; 'manual': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; '"you': 0.24; 'integrate': 0.24; 'unicode': 0.24; 'mon,': 0.24; 'cheers,': 0.24; "haven't": 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'query': 0.26; 'second': 0.26; 'pass': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'see,': 0.30; 'statement': 0.30; "i'm": 0.30; 'lines': 0.31; 'url:wiki': 0.31; 'quotes': 0.31; 'subject:that': 0.31; 'url:wikipedia': 0.31; 'yourself.': 0.31; 'guess': 0.33; 'subject:the': 0.34; 'common': 0.35; 'problem.': 0.35; 'skip:u 20': 0.35; 'version': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'being': 0.38; 'server': 0.38; 'sure': 0.39; 'how': 0.40; 'full': 0.61; 'new': 0.61; "you're": 0.61; 'content-disposition:inline': 0.62; "you'll": 0.62; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'combining': 0.68; 'subject:your': 0.76; '100%': 0.77; 'subject:have': 0.80; 'subject:SQL': 0.84; 'subject:check': 0.84; 'subject:NEW': 0.91; '2013': 0.98
Date Mon, 9 Dec 2013 09:32:04 +0000
From Daniel Watkins <daniel@daniel-watkins.co.uk>
To Jai <jaiprakashsingh213@gmail.com>
Subject Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1")
References <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <6b73a879-b490-48cb-a896-4d4abee90bf5@googlegroups.com>
User-Agent Mutt/1.5.21 (2010-09-15)
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3766.1386581533.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386581533 news.xs4all.nl 2968 [2001:888:2000:d::a6]:35737
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61373

Show key headers only | View raw


On Mon, Dec 09, 2013 at 12:41:57AM -0800, Jai wrote:
>         sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y)
>         sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore')
>         cursor.execute(sql)
> 
> 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1")

Though you haven't given the full traceback, I suspect that the lines
above are what is causing your problem.  My best guess is that you're
being hit by a form of SQL injection[0], in that the values you are
combining in to your query have single quotes which are resulting in an
SQL statement that looks like:

    insert into `category` (url, category, price) VALUES ('...', 'MEN'S SIZE 11.5 NEW IN BOX', '$49.99');

As you can see, the second value you are passing has mismatched quotes.
This is a common problem, so the MySQLdb library handles it by allowing
you to pass in the values you want to cursor.execute; it then takes care
of escaping them correctly:

    sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""
    cursor.execute(sql, (link1, x, y))

I'm not 100% sure what the Unicode normalisation is meant to be doing,
so you'll have to work out how to integrate that yourself.


Cheers,

Dan


[0] https://en.wikipedia.org/wiki/SQL_injection

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


Thread

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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Jai <jaiprakashsingh213@gmail.com> - 2013-12-09 00:41 -0800
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Daniel Watkins <daniel@daniel-watkins.co.uk> - 2013-12-09 09:32 +0000
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Chris Angelico <rosuav@gmail.com> - 2013-12-09 20:36 +1100
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") MRAB <python@mrabarnett.plus.com> - 2013-12-09 18:06 +0000
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Dan Stromberg <drsalists@gmail.com> - 2013-12-10 08:23 -0800
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") Chris Angelico <rosuav@gmail.com> - 2013-12-11 03:28 +1100
  Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") nowebdevmyrrh@gmail.com - 2014-02-25 09:37 -0800
    Re: 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 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1") MRAB <python@mrabarnett.plus.com> - 2014-02-25 18:10 +0000

csiph-web