MySQLdb: TypeError: not all arguments converted ...

Yermat loic at yermat.net1.nerim.net
Tue Oct 14 12:00:39 EDT 2003


"Achim Domma" <domma at procoders.net> a écrit dans le message de
news:bmgr00$g5c$06$1 at news.t-online.com
>> cursor.execute("insert into Webpages (Url) values (?)", (url,))
>> TypeError: not all arguments converted during string formatting
>
> I have solved it on my own, so just for the records: MySQLdb expects
> '%s' as placeholder, not '?' like adodbapi. Is the placeholder
> specified by the Python DB Api? Which one is wrong? Or is it an
> implementation detail?


Both, see http://www.python.org/peps/pep-0249.html
especially the following paragraph :

paramstyle

            String constant stating the type of parameter marker
            formatting expected by the interface. Possible values are
            [2]:

                'qmark'         Question mark style,
                                e.g. '...WHERE name=?'
                'numeric'       Numeric, positional style,
                                e.g. '...WHERE name=:1'
                'named'         Named style,
                                e.g. '...WHERE name=:name'
                'format'        ANSI C printf format codes,
                                e.g. '...WHERE name=%s'
                'pyformat'      Python extended format codes,
                                e.g. '...WHERE name=%(name)s'


I have a question too because of this because now how can I do if I want the
following request ?
self.sqlSelect  = "select * from %s where id='%s'" % self.__class__.__name__

-- 
Yermat






More information about the Python-list mailing list