Re: "ProgrammingError: can't adapt" when passing arguments to cursor.execute

Eric Chamberlain <Eric.Chamberlain-/Guk6kGqSwklJZD/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Would this be useful?  Makes the error more specific.  This code is a joke as I've never programmed in C/C++ so please laugh at my expense :)  I also have no idea what the process is when submitting a patch (I can't seem to find a trac or other issue tracking system for this project).

patch for version 2.0.13
psycopg/microprotocols.c
@ line 116

    char warning[] = "can't adapt object type '%s'. hint: register adaptor for type using psycopg2.extensions.register_adaptor().";
    /* -2 removes "%s" */
    char buff[sizeof(obj->ob_type->tp_name) + (sizeof(warning) - 2)];
    sprintf(buff, warning, obj->ob_type->tp_name);

    /* else set the right exception and return NULL */
    psyco_set_error(ProgrammingError, NULL, buff, NULL, NULL);

It works when I compile it... cheers!

Eric Chamberlain

On Nov 20, 2009, at 12:04 PM, Eric Chamberlain wrote:

> I had this same exact issue when I was using the suds SOAP library.  It was trying to cast a suds.sax.text.Text and couldn't adapt.  The trick was to put the variable in str().  In your case you may need to cast the numpy.float32 into a float with float().  Hope this helps.
>
> Eric Chamberlain
>
> On Nov 20, 2009, at 11:53 AM, William Carithers wrote:
>
>> Hi Federico,
>>
>> I thought this problem might need you to solve. The problem is probably the
>> numpy.float32 . Can I fix this with a cast? Would float(...the thing that is
>> numpy.float32...) work?
>> Here's the type list for the script:
>> <type 'int'>
>> <type 'int'>
>> <type 'int'>
>> <type 'numpy.float32'>
>> <type 'str'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'bool'>
>> <type 'numpy.float32'>
>> <type 'numpy.float32'>
>> <type 'numpy.float32'>
>> <type 'numpy.float32'>
>> <type 'numpy.float32'>
>> <type 'str'>
>>
>> Thanks,
>> Bill
>>
>> On 11/20/09 11:36 AM, "Federico Di Gregorio" <fog-NGVKUo/i/[email protected]> wrote:
>>
>>> Il giorno ven, 20/11/2009 alle 08.51 -0800, William Carithers ha scritto:
>>>> Thanks. I was worried about exactly that problem such as trying to load a
>>>> boolean into a column expecting a real. So I literally cut and pasted the
>>>> values from the "load" list in the script editor into the "load" list in the
>>>> interactive session. It worked in one case and not in the other. I'm not
>>>> sure why there is a roundoff difference but as long as values are consistent
>>>> about data types, I would think that it would be OK but at this point my
>>>> confidence level is pretty low.
>>>
>>> Hi,
>>>
>>> "can't adapt" has nothing to do with the destination types (the types of
>>> the backend columns). It is a Python problem: you passed to psycopg a
>>> type that psycopg does not know how to render into a string suitable to
>>> be passed to the backend.
>>>
>>> Can you please add something like:
>>>
>>> for x in load:
>>> print type(x)
>>>
>>> to your code and check every parameter type?
>>>
>>> federico
>>
>>
>> _______________________________________________
>> Psycopg mailing list
>> Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
>> http://lists.initd.org/mailman/listinfo/psycopg
>
>
> Confidentiality Notice: This e-mail may contain proprietary information some of which may be legally privileged. It is for the intended recipient(s) only. If you believe that it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution or use of this information by someone other than the intended recipient(s) is prohibited and may be unlawful.
> _______________________________________________
> Psycopg mailing list
> Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
> http://lists.initd.org/mailman/listinfo/psycopg


Confidentiality Notice: This e-mail may contain proprietary information some of which may be legally privileged. It is for the intended recipient(s) only. If you believe that it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution or use of this information by someone other than the intended recipient(s) is prohibited and may be unlawful.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.