List:General Discussion« Previous MessageNext Message »
From:Victor Subervi Date:October 5 2009 10:01pm
Subject:Re: No tuples, but AttributeError about tuple!
View as plain text  
Same error :(

On Mon, Oct 5, 2009 at 4:26 PM, DaWiz <dawiz@stripped> wrote:

> Vic tor,
>
> Try this instead:
>
> insert into products (ID, Name, Title, Description, Price, Bedrooms,
> Bathrooms, Conditions, Acreage, Construction, Location, Estate, Address,
> Furnished, pic1, pic2, pic3, pic4, pic5, pic6) values('1', 'name1',
> 'title1', 'descr1', '1.1', '2', '1', 'New', '1.5', 'new', 'princesse',
> 'princesse', '123 princesse', 'Not furnished', '', '', '', '', '', '');
>
> Values are enclosed in single quotes for SQL.
>
> ----- Original Message ----- From: "Victor Subervi" <
> victorsubervi@stripped>
> To: "Michael Dykman" <mdykman@stripped>; <mysql@stripped>
> Sent: Monday, October 05, 2009 2:33 PM
> Subject: Re: No tuples, but AttributeError about tuple!
>
>
>
> You were right about the % I'd forgotten. Still, I got the same error. So I
> tried to change the command to this:
>
> insert into products (ID, Name, Title, Description, Price, Bedrooms,
> Bathrooms, Conditions, Acreage, Construction, Location, Estate, Address,
> Furnished, pic1, pic2, pic3, pic4, pic5, pic6) values("1", "name1",
> "title1", "descr1", "1.1", "2", "1", "New", "1.5", "new", "princesse",
> "princesse", "123 princesse", "Not furnished", "", "", "", "", "", "");
>
> Here's the table description:
>
> (
> ID int(3) unsigned primary key auto_increment,
> Name varchar(40),
> Title varchar(3),
> Description varchar(512),
> Price float(10,2),
> Bedrooms int(1) unsigned,
> Bathrooms int(1) unsigned,
> Conditions varchar(255),
> Acreage float(5,2),
> Construction set('New','Existing'),
> Location varchar(256),
> Estate varchar(60),
> Address varchar(100),
> Furnished set('Furnished','Unfurnished'),
> pic1 blob,
> pic2 blob,
> pic3 blob,
> pic4 blob,
> pic5 blob,
> pic6 blob
> )
>
> Now I get this error:
>
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: Traceback (most recent call last):, referer:
> http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File
> "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in
> HandlerDispatch\n result = object(req), referer:
> http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File
> "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in
> handler\n imp.load_module(module_name, fd, path, desc), referer:
> http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File "/var/www/vhosts/
> 13gems.com/httpdocs/stxresort/cart/add_edit.py", line 360, in ?\n
> add_edit(), referer: http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File "/var/www/vhosts/
> 13gems.com/httpdocs/stxresort/cart/add_edit.py", line 314, in add_edit\n
> cursor.execute(sql), referer: http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File
> "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 163, in
> execute\n self.errorhandler(self, exc, value), referer:
> http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: File
> "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 35, in
> defaulterrorhandler\n raise errorclass, errorvalue, referer:
> http://13gems.com/stxresort/cart/iud.py
> [Mon Oct 05 13:23:36 2009] [error] [client 66.248.168.98] PythonHandler
> mod_python.cgihandler: OperationalError: (1054, "Unknown column 'Name' in
> 'field list'"), referer: http://13gems.com/stxresort/cart/iud.py
>
> Is it me, or does this actually make sense?
> TIA,
> V
>
>
> On Sun, Oct 4, 2009 at 7:20 PM, Michael Dykman <mdykman@stripped> wrote:
>
>  I assume you are using MySQLdb.
>>
>> to clarify, I trust you know that this is a tuple:
>> (id, name, title,
>>  description, price, bedrooms, bathrooms, conditions, acreage,
>> construction,
>>  location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5, pic6)
>>
>> ......
>>
>> I'm not exactly an expert in python but I don't follow this statement:
>>
>> >      sql = 'insert into products values(%s, %s, %s, %s, %s, %s, %s, %s,
>> %s,
>> > %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);', (id, name, title,
>> > description, price, bedrooms, bathrooms, conditions, acreage,
>> construction,
>> > location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5, >
>> pic6)
>> which is constructed as a = b,c and doesn't do what you think it does
>>
>> ..  if you were looking to do a text sprintf thing, it would be more
>> commonly
>>      sql = 'insert into products values(%s, %s, %s, %s, %s, %s, %s, %s,
>> %s,
>>  %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (id, name, title,
>>  description, price, bedrooms, bathrooms, conditions, acreage,
>> construction,
>>  location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5, pic6)
>>
>> which will not enquote your values. note the '%' operator between the
>> string and the tuple.
>>
>> what you want, I think is the 2 param form of cursor.execute() which
>> takes a string statement and a tuple of arguments:
>>
>> cursor.execute('insert into products values(%s, %s, %s, %s, %s, %s, %s,
>> %s,
>> %s,
>>  %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' , (id, name, title,
>>  description, price, bedrooms, bathrooms, conditions, acreage,
>> construction,
>>  location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5,
>> pic6))
>> conn.commit()
>>
>> execute knows how to address the various data types in the tuple and
>> will escape/enquote as necessary.
>>
>>  - michael
>>
>> Since you are
>>
>> On Sun, Oct 4, 2009 at 2:04 PM, Victor Subervi <victorsubervi@stripped>
>> wrote:
>> > Hi;
>> > I have the following python code:
>> >      sql = 'insert into products values(%s, %s, %s, %s, %s, %s, %s, %s,
>> %s,
>> > %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);', (id, name, title,
>> > description, price, bedrooms, bathrooms, conditions, acreage,
>> construction,
>> > location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5, >
>> pic6)
>> >      cursor.execute(sql)
>> >
>> > which, when printed to screen, gives the following:
>> >
>> > insert into products values ('1', 'name1', 'title1', 'descr1', '1.1',
>> '2',
>> > '1', 'New', '1.5', 'new', 'princesse', 'princesse', '123 princesse', >
>> 'Not
>> > furnished', '', '', '', '', '', '');
>> >
>> > which I can enter into the database directly. However, when I try to do
>> it
>> > through the script, I get the following error:
>> >
>> > AttributeError: 'tuple' object has no attribute 'encode'
>> >
>> > Why is that? There are no tuples here!! Nothing but strings!!
>> > TIA,
>> > Victor
>> >
>>
>>
>>
>> --
>>  - michael dykman
>>  - mdykman@stripped
>>
>> Don’t worry about people stealing your ideas. If they’re any good,
>> you’ll have to ram them down their throats!
>>
>>  Howard Aiken
>>
>>
>

Thread
No tuples, but AttributeError about tuple!Victor Subervi4 Oct
  • Re: No tuples, but AttributeError about tuple!Michael Dykman5 Oct
Re: No tuples, but AttributeError about tuple!Victor Subervi5 Oct
Re: No tuples, but AttributeError about tuple!Victor Subervi6 Oct