Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'list' object has no attribute '__values__' #1155

Open
renyhp opened this issue Oct 21, 2020 · 1 comment
Open

AttributeError: 'list' object has no attribute '__values__' #1155

renyhp opened this issue Oct 21, 2020 · 1 comment

Comments

@renyhp
Copy link

renyhp commented Oct 21, 2020

I'm trying to test an API which I don't have access to yet. So I went to mockable.io and pasted a sample response I got from the API provider. Here is my mockable configuration:
immagine

Here is the WDSL generated by mockable.

Python code:

>>> import pretend
>>> from zeep import Client
>>> from zeep.transports import Transport
>>> client = Client('http://demo6341126.mockable.io/?wsdl')
>>> response = pretend.stub(
...     status_code=200,
...     headers={},
...     content=b"""<?xml version="1.0" encoding="utf-8"?>
... <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
...   <soap:Body>
...     <TestResponse xmlns="http://tempuri.org/">
...       <TestResult>
...         <Test>
...           <field>string</field>
...           <status>string</status>
...         </Test>
...         <Test>
...           <field>string</field>
...           <status>string</status>
...         </Test>
...       </TestResult>
...     </TestResponse>
...   </soap:Body>
... </soap:Envelope>""")
>>> operation = client.service._binding._operations['MyTestAction']
>>> result = client.service._binding.process_reply(
...    client, operation, response)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/renyhp/testzeep/venv/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 231, in process_reply
    result = operation.process_reply(doc)
  File "/home/renyhp/testzeep/venv/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 430, in process_reply
    return self.output.deserialize(envelope)
  File "/home/renyhp/testzeep/venv/lib/python3.8/site-packages/zeep/wsdl/messages/soap.py", line 122, in deserialize
    result = next(iter(result.__values__.values()))
AttributeError: 'list' object has no attribute '__values__'

If the response contains multiple TestResults with one Test each, zeep throws no error. But it goes without saying that I have no control over the API responses.

I'm running zeep v4.0.0.

@Marek-Wojtowicz
Copy link

Marek-Wojtowicz commented Nov 5, 2020

My suggestion to correct the error:

diff --git a/src/zeep/wsdl/messages/soap.py b/src/zeep/wsdl/messages/soap.py
index 553bfa2..cda0cdb 100644
--- a/src/zeep/wsdl/messages/soap.py
+++ b/src/zeep/wsdl/messages/soap.py
@@ -119,6 +119,8 @@ class SoapMessage(ConcreteMessage):

         # Check if we can remove the wrapping object to make the return value
         # easier to use.
+        if not hasattr(result,'__values__'):
+            return result
         result = next(iter(result.__values__.values()))
         if isinstance(result, xsd.CompoundValue):
             children = result._xsd_type.elements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants