Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Need help with TypeError: cannot marshal None unless allow_none is enabled

By
Eric
on 5/21/14, 2:10 PM 3,372 views

Hello, I am trying to make an rpc call to the server which returns a set of data.  When I run my code I get this error:

 

Traceback (most recent call last):
  File "C:\Python27\Examples\customer_regreq_end_user.py", line 15, in <module>
    end_users = sock.execute('TestServerDB', uid, 'mds123', 'res.partner.end.user', 'get_partner_end_users')
  File "C:\Python27\lib\xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "C:\Python27\lib\xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "C:\Python27\lib\xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Python27\lib\xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "C:\Python27\lib\xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "C:\Python27\lib\xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
Fault: <Fault cannot marshal None unless allow_none is enabled: 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\OpenERP 7.0-20130722-231026\\Server\\server\\.\\openerp\\service\\wsgi_server.py", line 83, in xmlrpc_return\n  File "xmlrpclib.pyc", line 1132, in dumps\n  File "xmlrpclib.pyc", line 677, in dumps\n  File "xmlrpclib.pyc", line 699, in __dump\n  File "xmlrpclib.pyc", line 759, in dump_array\n  File "xmlrpclib.pyc", line 699, in __dump\n  File "xmlrpclib.pyc", line 759, in dump_array\n  File "xmlrpclib.pyc", line 699, in __dump\n  File "xmlrpclib.pyc", line 703, in dump_nil\nTypeError: cannot marshal None unless allow_none is enabled\n'>

 

Here is the script that calls the method:

    import xmlrpclib

    # Get the uid
    sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
    uid = sock_common.login('DB', 'admin', 'password')

    #replace localhost with the address of the server

    sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')

    end_users = sock.execute('DB', uid, 'password', 'res.partner.end.user', 'get_partner_end_users')

 

this is the method that is called:

    def get_partner_end_users(self, cr, uid, context=None):
            # Summary:
            # The end users are related to a partner_id
            # The user logging into the system will have a user_id and a partner_id
            # We need to look up the users record, then get the partner_id in order to find the end users

            # 1. Look up the user's record from res.users and find the partner_id value
            users_partner_id = self.pool.get('res.users').browse(cr, uid, uid).partner_id.id

            # 2. Use the partner_id to search for all related end users
            cr.execute('Select * from res_partner_end_user where partner_id = %d' % users_partner_id)
        
            # 3. Return the data set
            return cr.fetchall()

0
Jos De Graeve
On 5/22/14, 8:42 AM

Hello,

You should check the value of cr.fetchall() before returning:

res = cr.fetchall()

if not res:

    res=false

return res

The xmlrpc spec does not allow to send "None" as a value, that is why you get "Fault cannot marshal None", so you need to send False instead.

Regards,

Jos

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/21/14, 2:10 PM
Seen: 3372 times
Last updated: 3/16/15, 8:10 AM