xmlrpc errors not following standard

Asked by Marcos Mendez

When creating a partner with no fields, the xmlrpc response is below. not that the fault code should be a number as per spec. the fault string is empty.

<methodResponse>
 <fault>
  <value>
   <struct>
    <member>
     <name>faultCode</name>
     <value>
      <string>warning -- Integrity Error
       The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it
       - creation/update: a mandatory field is not correctly set [object with reference: name - name]</string>
     </value>
    </member>
    <member>
     <name>faultString</name>
     <value>
      <string />
     </value>
    </member>
   </struct>
  </value>
 </fault>
</methodResponse>

Question information

Language:
English Edit question
Status:
Open
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was originally filed as bug #1023429.

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#1

if you use the attached file you will get the following error:

Traceback (most recent call last):
  File "create_partner_nofields.py", line 15, in <module>
    sock = xmlrpclib.ServerProxy('%s/xmlrpc/common'%host)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1541, in __init__
    raise IOError, "unsupported XML-RPC protocol"
IOError: unsupported XML-RPC protocol

if you put a proxy in the middle, you will notice that the returned xml exception is not in the correct format.

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#2

Marcos,

I saw the file you attached and I found 2 issues within it:
1. You did not specify http:// over the URL for connection
 -->Set xmlrpclib.ServerProxy('http://%s/xmlrpc/object'%host)
2. You cannot create a partner record with no fields defined because there is a field 'name' which is a mandatory field (not-null constraint). You have to pass some value to the field name.
 ---> Traceback at server side:
   insert into "res_partner" (id,"customer","lang","vat_subjected","company_id","employee","supplier","active",create_uid,create_date) values (2,E'True',E'en_US',E'False',1,E'False',E'False',E'True',1,now())

Traceback (most recent call last):
  File "/server/bin/sql_db.py", line 132, in execute
    res = self._obj.execute(query, params)
IntegrityError: null value in column "name" violates not-null constraint

Hope this helps.

Thanks,
Serpent Consulting Services
http://www.serpentcs.com

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#3

1. attached the actual file. sorry sent wrong version.

2. this is not the error. this has not been solved. the error is not that we cannot do this. the error is that the xmlrpc response is in the incorrect format. please check the xml response i posted in the original email. the response does not follow the xmlrpc spec.

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#4

"""
:The login function is under
:: http://localhost:8069/xmlrpc/common
:For object retrieval use:
:: http://localhost:8069/xmlrpc/object
"""
import xmlrpclib

user = 'admin'
pwd = 'admin'
dbname = 'openerp_debug'
model = 'res.partner'
host = 'localhost:58778'
url = 'http://%s/xmlrpc/common'%host

print 'url',url
sock = xmlrpclib.ServerProxy(url)
uid = sock.login(dbname ,user ,pwd)
print 'uid', uid
sock = xmlrpclib.ServerProxy('%s/xmlrpc/object'%host)

# CREATE A PARTNER
partner_data = {}
partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#5

Not sure why it won't let me attach files any more. This is the updated version. Sorry sent it too quick again.

"""
:The login function is under
:: http://localhost:8069/xmlrpc/common
:For object retrieval use:
:: http://localhost:8069/xmlrpc/object
"""
import xmlrpclib

user = 'admin'
pwd = 'admin'
dbname = 'openerp_debug'
model = 'res.partner'
host = 'localhost:58778'
url1 = 'http://%s/xmlrpc/common'%host
url2 = 'http://%s/xmlrpc/object'%host

print 'url',url1
sock = xmlrpclib.ServerProxy(url1)
uid = sock.login(dbname ,user ,pwd)
print 'uid', uid
print 'url2',url2
sock = xmlrpclib.ServerProxy(url2)

# CREATE A PARTNER
partner_data = {}
partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#6

The response to this test is below and if you note it is not following the XMLRPC standard. The fault code should be an error, not a string. The fault string should be the string. This causes problems when using non-python xmlrpcclients.

This is the spec http://xmlrpc.scripting.com/spec.html, look at the fault example.

<methodResponse>
 <fault>
  <value>
   <struct>
    <member>
     <name>faultCode</name>
     <value>
      <string>warning -- Integrity Error
       The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it
       - creation/update: a mandatory field is not correctly set [object with reference: name - name]</string>
     </value>
    </member>
    <member>
     <name>faultString</name>
     <value>
      <string />
     </value>
    </member>
   </struct>
  </value>
 </fault>
</methodResponse>

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#7

Marcos,

I double checked and did not face the such format of response even with your file.

Please make sure the port belongs to xml-rpc.

How do you run this script?

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#8

I noticed this error while writing in a client in Java using the apache commons xmlrpcclient. The file tests the xmlrpc command, not the actual response.

The python client seems to handle an incorrect xmlrpc fault format. Java clients do not. So put a proxy in between to see the request and the response. I'm on mac so I used charles' proxy to see the responses from OpenERP.

I've added verbose to the example. You should see the response from the server.

body: "<?xml version='1.0'?>\n<methodResponse>\n<fault>\n<value><struct>\n<member>\n<name>faultCode</name>\n<value><string>warning -- Integrity Error\n\nThe operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set\n\n[object with reference: name - name]</string></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string></string></value>\n</member>\n</struct></value>\n</fault>\n</methodResponse>\n"

Again, the fault code should be a number. And the error there should be in the fault string.

On Jul 12, 2012, at 5:01 PM, Serpent Consulting Services wrote:

> Your question #202983 on OpenERP Server changed:
> https://answers.launchpad.net/openobject-server/+question/202983
>
> Status: Open => Answered
>
> Serpent Consulting Services proposed the following answer:
> Marcos,
>
> I double checked and did not face the such format of response even with
> your file.
>
> Please make sure the port belongs to xml-rpc.
>
> How do you run this script?
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/openobject-server/+question/202983/+confirm?answer_id=6
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/openobject-server/+question/202983
>
> You received this question notification because you asked the question.

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#9
Revision history for this message
Marcos Mendez (marcos-hr7) said :
#10

Nope. None of this works. This is an issue. The fault format being sent back is INCORRECT. It does not follow the spec.

The code is very simple and my code looks very similar to those listed. For example if you take the java-openerp-xmlrpc-libraries you mention. Download it and change their example.java to do the following you will get the same error. The xml response parser in the xml client tries to read the FAULT CODE as a number and it cannot, so it throws a ClassCastException.

-- example.java changes --

 public static void main(String[] args) throws MalformedURLException, XmlRpcException {
  example ex = new example();
// ex.relate();
        ex.createPartnerWithNoFields();
 }

 public example() throws MalformedURLException, XmlRpcException {
  openerp = new OpenERP("172.16.1.11", "openerp_debug", "admin", "admin");
 }

    public void createPartnerWithNoFields() {
        HashMap<String, Object> new1 = new HashMap<String, Object>();

        Integer new1_id = openerp.create("res.partner", new1);

        if (new1_id == null) {
            System.err.println("Something went wrong while creating a new stock.move");
        } else {
            System.out.println("created " + new1_id);
        }

    }

    public void createPartner() {
        HashMap<String, Object> new1 = new HashMap<String, Object>();
        new1.put("name","Test Partner");

        Integer new1_id = openerp.create("res.partner", new1);

        if (new1_id == null) {
            System.err.println("Something went wrong while creating a new stock.move");
        } else {
            System.out.println("created " + new1_id);
        }

    }

------- exception -----------

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
 at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)
 at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)
 at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
 at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
 at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
 at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
 at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
 at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
 at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
 at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
 at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
 at com.bremskerl.de.interfaces.openerp.OpenERP.create(OpenERP.java:647)
 at com.bremskerl.de.interfaces.openerp.example.createPartnerWithNoFields(example.java:37)
 at com.bremskerl.de.interfaces.openerp.example.main(example.java:16)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

On Jul 12, 2012, at 5:41 PM, Serpent Consulting Services wrote:

> Your question #202983 on OpenERP Server changed:
> https://answers.launchpad.net/openobject-server/+question/202983
>
> Status: Open => Answered
>
> Serpent Consulting Services proposed the following answer:
> Thanks for mentioning the right thing that this is experienced from java
> call.
>
> I guess any of these may help:
> http://selvam4u.wordpress.com/2010/12/09/openerp-xml-rpc-java/
> https://code.launchpad.net/~dieck/openobject-server/java-openerp-xmlrpc-libraries
> http://code.google.com/p/openerpclient-java/source/checkout
> http://stackoverflow.com/questions/11112876/xmlrpc-java-insert-issue
>
> Good luck.
>
> Thanks.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/openobject-server/+question/202983/+confirm?answer_id=8
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/openobject-server/+question/202983
>
> You received this question notification because you asked the question.

Revision history for this message
Marcos Mendez (marcos-hr7) said :
#11

Additional example. Send incorrect verb thru xmlrpc. Response is two strings, again, not following the standard.

<methodResponse>
 <fault>
  <value>
   <struct>
    <member>
     <name>faultCode</name>
     <value>
      <string>'res.partner' object has no attribute 'READ'</string>
     </value>
    </member>
    <member>
     <name>faultString</name>
     <value>
      <string>Traceback (most recent call last):
       File "/usr/lib/pymodules/python2.7/openerp/wsgi/core.py", line 79, in xmlrpc_return result = openerp.netsvc.dispatch_rpc(service, method, params)
       File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 360, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params)
       File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 572, in dispatch res = fn(db, uid, *params)
       File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 121, in wrapper return f(self, dbname, *args, **kwargs)
       File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 176, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw)
       File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 164, in execute_cr return getattr(object, method)(cr, uid, *args, **kw)
       AttributeError: 'res.partner' object has no attribute 'READ' </string>
     </value>
    </member>
   </struct>
  </value>
 </fault>
</methodResponse>

Can you help with this problem?

Provide an answer of your own, or ask Marcos Mendez for more information if necessary.

To post a message you must log in.