0

when I integrate the "WSGISOAPHandler" the SOAP server don't work. Any ideas? When the client call to server, the server returns "can't use a string pattern on a bytes-like object"

if __name__ == "__main__":

    def ota_vehlocsearch(respuesta):
        return "respuesta"

    dispatcher = SoapDispatcher(
        name='soap',
        location = "http://localhost:8008/",
        action = 'http://localhost:8008/', # SOAPAction
        namespace = "http://www.opentravel.org/OTA/2003/05", prefix="ns0",
        trace = True,
        ns = True)

    dispatcher.register_function('OTA_VehLocSearch', ota_vehlocsearch,
        returns={'Result': str},
        args={'call': str})

    print("Starting wsgi server...")
    from wsgiref.simple_server import make_server
    application = WSGISOAPHandler(dispatcher)
    wsgid = make_server('localhost', 8008, application)
    wsgid.serve_forever()
Jordi Salom
  • 361
  • 2
  • 5
  • 14
  • which soap library are you using? pysimplesoap? Which version? Also please try to get the exact traceback from the server side which will likely help. – Felix Schwarz Feb 05 '16 at 23:04
  • Thanks for your answer Felix. I'm working with pysimplesoap 1.6 and python 3.4 – Jordi Salom Feb 08 '16 at 08:16
  • Any luck in capturing a traceback? Also try to upgrade to the latest pysimplesoap (shot in the dark). Could you provide some full test case? I can run your example but don't see an error (presumable because that only happens when a client tries to retrieve something from your server) – Felix Schwarz Feb 08 '16 at 11:38

1 Answers1

0

This question never got an answer. I never got the WSGISOAPHandler(dispatcher) to work either since it would always throw assert type(data) is bytes, "write() argument must be a bytes instance" in /usr/lib/python3.8/wsgiref/handlers.py on line 297. Since wsgiref.simple_server import make_server is from python2 which treats encoding differently i just decided instead to use from http.server import HTTPServer to avoid all these encoding issues.

Here is an example i made using a Client and Server:

Server:

from pysimplesoap.server import SoapDispatcher, SOAPHandler
from http.server import HTTPServer

def cityweatherreport(city_name):
    #Some Code here to fetch weather info:
    weather_report = f"""Weather in {city_name} is """
    print('weather_report: ', weather_report)
    return{'weather_report': weather_report}

def server_accepting_soap_requests():
    dispatcher = SoapDispatcher(
    name="WeatherServer",
    location="http://127.0.0.1:8050/",
    action='http://127.0.0.1:8050/', # SOAPAction
    namespace="http://example.com/pysimplesoapsamle/",
    prefix="ns0",
    trace = True,
    ns = True)
    dispatcher.register_function('CityWeatherReport', cityweatherreport,
        returns={'weather_report': str},
        args={'city_name': str})
    print('starting server')
    httpd = HTTPServer(("", 8050), SOAPHandler)
    httpd.dispatcher = dispatcher
    httpd.serve_forever()

def main():
    server_accepting_soap_requests()

if __name__ == '__main__':
    main()

Client:

from pysimplesoap.client import SoapClient

def test_weather_conversion_service():
    client = SoapClient(
    location="http://localhost:8050/",
    action='http://localhost:8050/',  # SOAPAction
    namespace="http://example.com/sample.wsdl",
    soap_ns='soap',
    trace=True,
    ns="ns0",
    )
    response = client.CityWeatherReport(city_name="Berlin")
    result = response.weather_report
    print('result: ', result)

def main():
    test_weather_conversion_service()

if __name__ == '__main__':
    main()

For running it remote on a dedicated machine i would suggest a tool like screen: screen -d -m -S <username> python3 <pythonfile.py>

jenz
  • 23
  • 1
  • 7