#87 TypeError: object does not support item assignment

Andy Dustman
MySQLdb (285)

On FreeBSD 4.9 with:
- python 2.3.4,
- apache 2.0.49,
- mod_python 3.1.3
- mysql Ver 11.18 Distrib 3.23.58, for portbld-
freebsd4.9 (i386)

this code:

import MySQLdb
db = MySQLdb.connect(host="localhost", user="joe",

results with this error:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/site-
packages/MySQLdb/init.py", line 64, in Connect
return apply(Connection, args, kwargs)
File "/usr/local/lib/python2.3/site-
packages/MySQLdb/connections.py", line 117, in init
self.converter[types.StringType] = self.string_literal
TypeError: object does not support item assignment


  • beat birkhofer
    beat birkhofer

    Logged In: YES

    Happens with

    Python 2.3.4 (#1, May 30 2004, 13:16:44)
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

    mysql Ver 12.22 Distrib 4.0.18, for apple-darwin7.3.0 (powerpc)

    on MacOSX 10.3.4

    (but does not happen with python 2.2/mysql 4.0.17/MacOSX 10.2.8)

  • Andy Dustman
    Andy Dustman

    Logged In: YES

    In connections.Connection.init, try inserting this line
    immediately before the line that is raising the exception:

    print 'conv = ', kwargs2['conv']

    This should be a dictionary (normally).

  • beat birkhofer
    beat birkhofer

    Logged In: YES


    conv = {0: <type 'float'="">, 1: <type 'int'="">, 2: <type 'int'="">, 3: <type 'long'="">, <type 'tuple'="">: <built-in function="" escape_sequence="">, 5: <type 'float'="">, 7: <function mysql_timestamp_converter="" at="" 0x38fef0="">, 8: <type 'long'="">, 9:
    <type 'int'="">, 10: <function Date_or_None="" at="" 0x38faf0="">, 11:
    <function Time_or_None="" at="" 0x38f730="">, 12: <function DateTime_or_None="" at="" 0x38f6b0="">, 13: <type 'int'="">, <type 'float'="">: <function Float2Str="" at="" 0x398930="">, 252: [(128,
    <function char_array="" at="" 0x398a30="">), (None, <function <lambda=""> at 0x398eb0>), (None, None)]
    , <type 'int'="">:
    <function Thing2Str="" at="" 0x394cb0="">, 4: <type 'float'="">, <type 'array.array'="">: <function array2Str="" at="" 0x398a70="">, <type 'NoneType'="">: <function None2NULL="" at="" 0x398970="">, <type 'instance'="">: <function Instance2Str="" at="" 0x3989f0="">, <type 'dict'="">: <built-in function="" escape_dict="">, <type 'unicode'="">:
    <function Unicode2Str="" at="" 0x394d70="">, 253: <function <lambda="">
    at 0x398eb0>, <type 'str'="">: <function Thing2Literal="" at="" 0x3989b0="">, <type 'list'="">: <built-in function="" escape_sequence="">, 248: <function Str2Set="" at="" 0x394530="">, <type 'long'="">: <function Thing2Str="" at="" 0x394cb0="">, <type 'type'="">:
    <function DateTimeDelta2literal="" at="" 0x38feb0="">, <type 'object'="">: <function Instance2Str="" at="" 0x3989f0="">, 254:
    <function <lambda=""> at 0x398eb0>}

    [MacOSX/Python 2.3.4]

  • perica

    Logged In: YES

    this is what I have after print:

    conv = {0: <type 'float'="">, 1: <type 'int'="">, 2: <type 'int'="">, 3:
    <type 'long'="">, 4: <type 'float'="">, 5: <type 'float'="">,
    <type 'int'="">: <function Thing2Str="" at="" 0x81be95c="">, 7:
    <function mysql_timestamp_converter="" at="" 0x81be844="">, 8:
    <type 'long'="">, 9: <type 'int'="">, 10: <function Date_or_None="" at="" 0x81be7d4="">, 11: <function Time_or_None="" at="" 0x81be79c="">,
    12: <function DateTime_or_None="" at="" 0x81be72c="">, 13:
    <type 'int'="">, <type 'list'="">: <built-in function="" escape_sequence="">, <type 'type'="">: <function DateTimeDelta2literal="" at="" 0x81be80c="">, <type 'float'="">:
    <function Float2Str="" at="" 0x81d987c="">, <type 'instance'="">:
    <function Instance2Str="" at="" 0x81d9924="">, <type 'array.array'="">:
    <function array2Str="" at="" 0x81d9994="">, <type 'object'="">:
    <function Instance2Str="" at="" 0x81d9924="">, <type 'dict'="">: <built- in="" function="" escape_dict="">, <type 'str'="">: <function Thing2Literal="" at="" 0x81d98ec="">, <type 'NoneType'="">: <function None2NULL="" at="" 0x81d98b4="">, <type 'long'="">: <function Thing2Str="" at="" 0x81be95c="">, <type 'unicode'="">: <function Unicode2Str="" at="" 0x81d964c="">, 248: <function Str2Set="" at="" 0x81be924="">, <type 'tuple'="">: <built-in function="" escape_sequence="">, 252: [(128, <function char_array="" at="" 0x81d995c="">), (None, None)]}

  • Andy Dustman
    Andy Dustman

    Logged In: YES

    conv (in kwargs2) is passed to the
    _mysql.Connection.init() method as a keyword arg.
    There's no way can see
    (_mysql.c:_mysql_ConnectionObject_Initialize() 428-533 in
    1.0.0) for that value to ever be None. If no value of conv
    is passed, it's initialized with a new dictionary; see 471-479.

    Some other things to try:

    1) After printing the value of kwargs2['conv'], print

    2) _mysql.c has this for member access:

    1929 MyMember(
    1930 "converter",
    1931 T_OBJECT,
    1933 0,
    1934 "Type conversion mapping"
    1935 ),

    Change the 0 on 1933 to RO. Rebuild and reinstall.

  • beat birkhofer
    beat birkhofer

    Logged In: YES

    With this modification it works for me. self.converter is of
    type 'dict'.

  • perica

    Logged In: YES

    I tried 1) and printed value is "None" I also changed 2) but
    same error again...

  • Andy Dustman
    Andy Dustman

    Logged In: YES

    Beat, which modification fixed it for you?

  • beat birkhofer
    beat birkhofer

    Logged In: YES


    Anyway I have to comment out the crypt library in setup.py
    (lines 40 and 41) and then change Line 1933 in _mysql.c.
    That's all (in 1.1.1).

    Beat H.

  • perica

    Logged In: YES

    I tried with commenting out lines 40&41 in setup.py and after
    recompile and reinstall still same problem... what am I doing

  • Andy Dustman
    Andy Dustman

    Logged In: YES

    One thing that complicates the issue is that the strucure
    used to define member access changed in Python 2.2 to
    support doc strings, so the code is a little complicated.
    One of the action items in 1.1 is to remove support for
    pre-2.2 Python, so it should become simpler and maybe I'll
    see something I missed. However, I am beginning to wonder if
    this is not a subtle bug in Python that only manifests on
    some platforms.

    I'll try to get a 1.1 release out this weekend to test it.

  • Logged In: NO

    Having the same problem on Mac OSX 10.3.4, Python 2.2.2 (#1, 06/16/
    03, 04:22:47)
    [GCC Apple cpp-precomp 6.14] on darwin
    MySQL 4.0.15 from Server Logisics (the "CompleteMySQL" package)

    Have tried commenting out the crypto lines, have also changed the "0" to
    "R0" in the file mentioned.

    The result I get is:

    running build_ext
    building '_mysql' extension
    gcc -DNDEBUG -O3 -Wall -Wstrict-prototypes -I/Library/MySQL/include/
    mysql -I/usr/include/mysql -I/usr/local/include/mysql -I/usr/local/mysql/
    include -I/usr/local/mysql/include/mysql -I/sw/include/mysql -I/sw/
    include/python2.2 -c _mysql.c -o build/temp.darwin-7.4.0-
    _mysql.c:1929: R0' undeclared here (not in a function) _mysql.c:1929: initializer element is not constant _mysql.c:1929: (near initialization for_mysql_ConnectionObject_memberlist[1].flags')
    _mysql.c:1929: initializer element is not constant
    _mysql.c:1929: (near initialization for
    _mysql_ConnectionObject_memberlist[1]') _mysql.c:1936: initializer element is not constant _mysql.c:1936: (near initialization for_mysql_ConnectionObject_memberlist[2]')
    _mysql.c:1943: initializer element is not constant
    _mysql.c:1943: (near initialization for
    _mysql_ConnectionObject_memberlist[3]') _mysql.c:1950: initializer element is not constant _mysql.c:1950: (near initialization for_mysql_ConnectionObject_memberlist[4]')
    _mysql.c:1957: initializer element is not constant
    _mysql.c:1957: (near initialization for
    error: command 'gcc' failed with exit status 1

    I'm not very good at interpreting these, but I'm guessing it doesn't like
    the fact that I've changed the 0 to R0.

    Any ideas as to what to do?

    Andrew (andymorris84@netscape.net)

  • Logged In: NO

    Same "nobody" as 10 seconds ago, I'm assuming the .c file I was meant
    to change was the one in the MySQLdb tar file, rather than one anywhere
    else on the HD, if not then this could explain it.............


  • Andy Dustman
    Andy Dustman

    Logged In: YES

    It's RO, as in "read-only", not R0, as in "Arrr-zero". R0
    won't do anything but produce compiler errors.

    Can you reproduce exactly the steps you are using to build
    and install on Mac OS X? Start with a clean, unmodified file
    set, and include everything you do starting with unpacking
    the files.

  • Logged In: NO

    To build and install MySQLdb......... as best I can remember it

    Download the package.
    Untar it using the tar app, rather than Stuffit
    Edit setup.py, because the Server Logistics installs MySQL in an odd
    location (/Library/MySQL), to add the include and lib directories to the
    list of ones its meant to search for, and to comment out the crypto lines.
    Edit the .c file, as explained here.
    Run setup.py build
    Sometimes it had problems with directory permissions on the /sw/lib/
    python-2.2/site-packages directory, it needed to copy and delete a
    mysql.so file (I think, definitely a .so), so in that case I'd mess around
    changing the permissions so that it could do that - it would run OK after
    Run setup.py install

    Thats all I can think of, if you want more detail then email me
    (andymorris84@netscape.net) and I'll try and get some more detail.

    It works now, at the moment, thanks,


  • Andy Dustman
    Andy Dustman

    Logged In: YES

    Reopen if you can replicate this with 1.1.4. Include a
    complete log of how you built and installed it.