Re: MySQLdb insert HTML code error
On Tue, Dec 11, 2012 at 11:46 AM, Anatoli Hristov toli...@gmail.com wrote: Brilliant, I think your problem is in line 97 of the code that you *HAVEN'T QUOTED*. Please go here, read and inwardly digest before you say anything else http://www.sscce.org/ :) I thought it was clear. the spec is the description and when the strspec contains the html code I'm getting an error, if you don't want to help then just don't become an.. SSCCE starts with Short. The HTML you unloaded into that email hardly qualifies. When you're trying to figure out a problem that appears to happen only when you have X and not when you have Y, see what the smallest example data for X and Y are that continue to exhibit the difference. It's way easier, especially on those of us who might have been interested in helping, had it been possible to paste your failing code into IDLE. Plus, in cutting it down you might discover what the real cause of the problem is. Of course, sometimes you fail to cut something down as expected. In this example, HTML didn't turn out to be the problem, so cutting it down to html/html wouldn't have worked. But do at least _try_, and then mention what worked and didn't work in your question. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
SSCCE starts with Short. The HTML you unloaded into that email hardly qualifies. When you're trying to figure out a problem that appears to happen only when you have X and not when you have Y, see what the smallest example data for X and Y are that continue to exhibit the difference. It's way easier, especially on those of us who might have been interested in helping, had it been possible to paste your failing code into IDLE. Plus, in cutting it down you might discover what the real cause of the problem is. Of course, sometimes you fail to cut something down as expected. In this example, HTML didn't turn out to be the problem, so cutting it down to html/html wouldn't have worked. But do at least _try_, and then mention what worked and didn't work in your question. This is the reason I posted in the beginning only the part with the problem function. -after I posted the all string (the HTML) as there was some miss understandings: -I will try to follow the (sscce) next time, excuse me as I'm a beginner in coding at all. Regards -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb insert HTML code error
Hi all, I'm facing an issue inserting an html code into the DB, it comes out with a syntax error but I face it only when I have html code. Could help me escape the error somehow ? Here is my code def InsertSpecsDB(product_id, spec, lang, name): db = MySQLdb.connect(localhost,getit,opencart) cursor = db.cursor() sql = (INSERT INTO product_description (product_id, language_id, name, description) VALUES ('%s','%s','%s','%s')) params = (product_id, lang, name, spec) cursor.execute(sql, params) id = cursor.lastrowid printUpdated ID %s description %s %(int(id), lang) return id Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
On 11/12/2012 00:04, Anatoli Hristov wrote: Hi all, I'm facing an issue inserting an html code into the DB, it comes out with a syntax error but I face it only when I have html code. Could help me escape the error somehow ? Here is my code def InsertSpecsDB(product_id, spec, lang, name): db = MySQLdb.connect(localhost,getit,opencart) cursor = db.cursor() sql = (INSERT INTO product_description (product_id, language_id, name, description) VALUES ('%s','%s','%s','%s')) params = (product_id, lang, name, spec) cursor.execute(sql, params) id = cursor.lastrowid printUpdated ID %s description %s %(int(id), lang) return id Thanks As much use as a chocolate teapot, all you've given is a function/method definition. No indication of your OS, Python version, calling code, what you expect to happen, what actually happened, apart from that your request for assistance is perfect. Usually I'd be able to help but sadly my crystal ball is in for repairs at the moment. Would you please be kind enough to elucidate. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
As much use as a chocolate teapot, all you've given is a function/method definition. No indication of your OS, Python version, calling code, what you expect to happen, what actually happened, apart from that your request for assistance is perfect. Usually I'd be able to help but sadly my crystal ball is in for repairs at the moment. Would you please be kind enough to elucidate. Thanks for your answer, the OS is CentOS release 5.7. MySQL - 5.0.96 As I said the function is working right, except when I insert an HTML code. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
On Tue, Dec 11, 2012 at 1:29 AM, Anatoli Hristov toli...@gmail.com wrote: As much use as a chocolate teapot, all you've given is a function/method definition. No indication of your OS, Python version, calling code, what you expect to happen, what actually happened, apart from that your request for assistance is perfect. Usually I'd be able to help but sadly my crystal ball is in for repairs at the moment. Would you please be kind enough to elucidate. Thanks for your answer, the OS is CentOS release 5.7. MySQL - 5.0.96 As I said the function is working right, except when I insert an HTML code. Thanks And sorry, Python 2.4 -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
On 11/12/2012 00:29, Anatoli Hristov wrote: As much use as a chocolate teapot, all you've given is a function/method definition. No indication of your OS, Python version, calling code, what you expect to happen, what actually happened, apart from that your request for assistance is perfect. Usually I'd be able to help but sadly my crystal ball is in for repairs at the moment. Would you please be kind enough to elucidate. Thanks for your answer, the OS is CentOS release 5.7. MySQL - 5.0.96 As I said the function is working right, except when I insert an HTML code. Thanks Brilliant, I think your problem is in line 97 of the code that you *HAVEN'T QUOTED*. Please go here, read and inwardly digest before you say anything else http://www.sscce.org/ -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
On 2012-12-11 00:04, Anatoli Hristov wrote: Hi all, I'm facing an issue inserting an html code into the DB, it comes out with a syntax error but I face it only when I have html code. Could help me escape the error somehow ? Here is my code def InsertSpecsDB(product_id, spec, lang, name): db = MySQLdb.connect(localhost,getit,opencart) cursor = db.cursor() sql = (INSERT INTO product_description (product_id, language_id, name, description) VALUES ('%s','%s','%s','%s')) params = (product_id, lang, name, spec) cursor.execute(sql, params) id = cursor.lastrowid printUpdated ID %s description %s %(int(id), lang) return id You're using a parametrised query (which is good :-)), but you've included quotes around the placeholders. There's no need to do that. They'll be quoted automatically when necessary: sql = INSERT INTO product_description (product_id, language_id, name, description) VALUES (%s,%s,%s,%s) -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
You're using a parametrised query (which is good :-)), but you've included quotes around the placeholders. There's no need to do that. They'll be quoted automatically when necessary: sql = INSERT INTO product_description (product_id, language_id, name, description) VALUES (%s,%s,%s,%s) Thanks a lot it wrks. I was looking in the wrong direction (escape str. raw etc) Thanks again :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb insert HTML code error
First thing -- DON'T put quotes around the %s place-holders... The whole purpose of using the parameterized .execute() is to let the database adapter properly escape the parameters before putting them into the SQL (since MySQL didn't have prepared statements before v5, it was producing full SQL statements for each insert, even with .executemany() ) Thank you, this solved my problem.:) -- http://mail.python.org/mailman/listinfo/python-list