No tuples, but AttributeError about tuple!
No tuples, but AttributeError about tuple!
am 04.10.2009 20:04:40 von Victor Subervi
--0016e64ba3fabf151a04751fd47b
Content-Type: text/plain; charset=ISO-8859-1
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
--0016e64ba3fabf151a04751fd47b--
Re: No tuples, but AttributeError about tuple!
am 05.10.2009 02:10:39 von Michael Dykman
This looks like much more of a python question than a MySQL question..
I'll reply offline.
- michael dykman
On Sun, Oct 4, 2009 at 2:04 PM, Victor Subervi wr=
ote:
> Hi;
> I have the following python code:
> =A0 =A0 =A0sql =3D '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, constructio=
n,
> location, estate, address, furnished, pic1, pic2, pic3, pic4, pic5, pic6)
> =A0 =A0 =A0cursor.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 i=
t
> 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
>
--=20
- michael dykman
- mdykman@gmail.com
Don=92t worry about people stealing your ideas. If they=92re any good,
you=92ll have to ram them down their throats!
Howard Aiken
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: No tuples, but AttributeError about tuple!
am 05.10.2009 22:33:39 von Victor Subervi
--00151758f83e5e8286047536079e
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
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 =3D 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 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 =3D '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, pic=
6)
> which is constructed as a =3D 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 =3D '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
> wrote:
> > Hi;
> > I have the following python code:
> > sql =3D '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, pic=
6)
> > 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', 'N=
ot
> > 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@gmail.com
>
> Don=92t worry about people stealing your ideas. If they=92re any good,
> you=92ll have to ram them down their throats!
>
> Howard Aiken
>
--00151758f83e5e8286047536079e--
Re: No tuples, but AttributeError about tuple!
am 06.10.2009 00:01:08 von Victor Subervi
--0016368342a441f54204753740f4
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Same error :(
On Mon, Oct 5, 2009 at 4:26 PM, DaWiz 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@gmail.com>
> To: "Michael Dykman" ;
> 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 =3D 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, i=
n
> 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 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, pic=
6)
>>
>> ......
>>
>> I'm not exactly an expert in python but I don't follow this statement:
>>
>> > sql =3D '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 =3D 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 =3D '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, pic=
6)
>>
>> 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
>> wrote:
>> > Hi;
>> > I have the following python code:
>> > sql =3D '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 d=
o
>> 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@gmail.com
>>
>> Don=92t worry about people stealing your ideas. If they=92re any good,
>> you=92ll have to ram them down their throats!
>>
>> Howard Aiken
>>
>>
>
--0016368342a441f54204753740f4--