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

create_service for AsyncClient #1168

Open
jenson2486 opened this issue Nov 18, 2020 · 3 comments
Open

create_service for AsyncClient #1168

jenson2486 opened this issue Nov 18, 2020 · 3 comments

Comments

@jenson2486
Copy link

jenson2486 commented Nov 18, 2020

Version: zeep 4.0.0
WSDL: 'http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL'

Hi guys,
i am starting developing a soap interface based on zeep. Our application works mostly async, so I try to use the AsyncClient. Additional I test the interface against a mock, placed in soap_ui. For using the mock, it is necessary to define the endpoint to the mock, so I used the create_service method.

client = AsyncClient(wsdl='http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL')
service = client.create_service('{http://www.dataaccess.com/webservicesserver/}NumberConversionSoapBinding',
                                'http://[replaced]:8088/mockNumberConversionSoapBinding')
loop = asyncio.new_event_loop()
print(loop.run_until_complete(service.NumberToDollars(2)))

The expception log:

Traceback (most recent call last):
  File ".\tests\minimal_examples\soap.py", line 46, in <module>
    print(loop.run_until_complete(service.NumberToDollars(2)))
  File "[replaced]\.tox\dev\lib\site-packages\zeep\proxy.py", line 46, in __call__
    return self._proxy._binding.send(
  File "[replaced]\.tox\dev\lib\site-packages\zeep\wsdl\bindings\soap.py", line 135, in send
    return self.process_reply(client, operation_obj, response)
  File "[replaced]\.tox\dev\lib\site-packages\zeep\wsdl\bindings\soap.py", line 177, in process_reply
    if response.status_code in (201, 202) and not response.content:
AttributeError: 'coroutine' object has no attribute 'status_code'
sys:1: RuntimeWarning: coroutine 'AsyncTransport.post_xml' was never awaited

After some research, the reason is the create_service method, defined in the sync client, which returns a sync ServiceProxy object, but exected will be a AsyncServiceProxy object.

Is my assumption right?

BR Jens

@william-davis-od
Copy link

Your assumption is correct, I just had the same issue. I resolved in my project by creating a custom class that extends the AsyncClient class and overrides the create_service method to return an AsyncServiceProxy:

   def create_service(self, binding_name, address):
        """Create a new AsyncServiceProxy for the given binding name and address.

        :param binding_name: The QName of the binding
        :param address: The address of the endpoint

        """
        try:
            binding = self.wsdl.bindings[binding_name]
        except KeyError:
            raise ValueError(
                "No binding found with the given QName. Available bindings "
                "are: %s" % (", ".join(self.wsdl.bindings.keys()))
            )
        return AsyncServiceProxy(self, binding, address=address)

@jlvrhee
Copy link

jlvrhee commented Feb 2, 2021

We had the same problem in our project and had to solve it the same way.

Can this solution be merged into zeep itself?

@phillipuniverse
Copy link

This is fixed in #1202 but not sure why it's still unmerged.

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

Successfully merging a pull request may close this issue.

4 participants