GithubHelp home page GithubHelp logo

Comments (6)

mvantellingen avatar mvantellingen commented on August 17, 2024

Just a quick initial guess: The value is an anyType, can you use the following: http://docs.python-zeep.org/en/latest/#any-objects (that is wrap the value in an xsd.anyObject)

from python-zeep.

cheuel-laird avatar cheuel-laird commented on August 17, 2024

I changed the code so that I use the AnyObject class, but still does not convert it to the correct values:

new_value_type = edp.get_type("{http://ws.polarion.com/types}Text")

any_val = xsd.AnyObject(new_value_type, new_value_type(type = "text/html", content="This is a first Test", contentLossy=False))
new_solution_type = edp.get_type("{http://ws.polarion.com/TrackerWebService-types}CustomField")

sol = new_solution_type(key="solution", parentItemURI=uri, value=any_val)
edp.service.setCustomField(sol)

The send packet looks like this:

<ns0:setCustomField>
<ns0:customField>
<ns2:parentItemURI>subterra:data-service:objects:/default/sw_team_linux${WorkItem}SWTLI-664</ns2:parentItemURI>
<ns2:key>solution</ns2:key>
<ns2:value>&lt;zeep.xsd.types.AnyObject object at 0x7f995e4f89b0&gt;</ns2:value>
</ns0:customField>
</ns0:setCustomField>

from python-zeep.

mvantellingen avatar mvantellingen commented on August 17, 2024

So the issue was that I used xsd.String() as default type for elements while it should have been anyType (ur-type). Can you give the master branch a try?

This seems to generate valid xml:

import zeep
from lxml import etree
from zeep import xsd

client = zeep.Client('http://almdemo.polarion.com/polarion/ws/services/TrackerWebService?wsdl')
new_value_type = client.get_type("{http://ws.polarion.com/types}Text")
value = xsd.AnyObject(
    new_value_type,
    new_value_type(type="text/html", content="This is a first Test", contentLossy=False))

new_solution_type = client.get_type("{http://ws.polarion.com/TrackerWebService-types}CustomField")
sol = new_solution_type(
    key='solution',
    parentItemURI='subterra:data-service:objects:/default/sw${WorkItem}LI-66',
    value=value)

# Dump the message which would be created
node = client.service._binding.create_message('setCustomField', sol)
print(etree.tostring(node, pretty_print=True))

from python-zeep.

cheuel-laird avatar cheuel-laird commented on August 17, 2024

I tried the master branch, but it gives me an error:

File "/usr/lib/python3/dist-packages/zeep/wsdl/definitions.py", line 224, in create
return self.input.serialize(_args, *_kwargs)
File "/usr/lib/python3/dist-packages/zeep/wsdl/messages.py", line 70, in serialize
self.body.render(body, body_value)
File "/usr/lib/python3/dist-packages/zeep/xsd/elements.py", line 99, in render
return self.type.render(node, value)
File "/usr/lib/python3/dist-packages/zeep/xsd/types.py", line 130, in render
element.render(parent, sub_value)
File "/usr/lib/python3/dist-packages/zeep/xsd/elements.py", line 99, in render
return self.type.render(node, value)
File "/usr/lib/python3/dist-packages/zeep/xsd/types.py", line 130, in render
element.render(parent, sub_value)
File "/usr/lib/python3/dist-packages/zeep/xsd/elements.py", line 99, in render
return self.type.render(node, value)
File "/usr/lib/python3/dist-packages/zeep/xsd/builtins.py", line 444, in render
parent.text = self.xmlvalue(value)
File "src/lxml/lxml.etree.pyx", line 1031, in lxml.etree._Element.text.set (src/lxml/lxml.etree.c:55347)
File "src/lxml/apihelpers.pxi", line 711, in lxml.etree._setNodeText (src/lxml/lxml.etree.c:24667)
File "src/lxml/apihelpers.pxi", line 699, in lxml.etree._createTextNode (src/lxml/lxml.etree.c:24516)
File "src/lxml/apihelpers.pxi", line 1437, in lxml.etree._utf8 (src/lxml/lxml.etree.c:32414)
TypeError: Argument must be bytes or unicode, got 'Text'

from python-zeep.

mvantellingen avatar mvantellingen commented on August 17, 2024

Did you wrap the Text type in an AnyObject() like in my code snippet?

Error message should be more helpful nonetheless :-)

from python-zeep.

cheuel-laird avatar cheuel-laird commented on August 17, 2024

Arg, sorry, no, I didn't. I thought I didn't change my code.
Wrapping it with AnyObject fixes this. Thanks!

Is this somehow related to #17 ?

from python-zeep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.