Problem wtih httplib and winsock

Mark Russell mrussell8081 at pacbell.net
Wed May 15 16:17:58 EDT 2002


Hi to all,

I am working through a simple SOAP example from the IBM developer developer
series.  The full article is here:
http://www-106.ibm.com/developerworks/webservices/library/ws-pyth6/?dwzone=w
ebservices

My platform is Python 2.2 on Win2K.  On the client side I need to use
httplib to make a request of a SOAP.py based service.  Every time I run the
client I get a winsock error.  The client and server code is reproduced
below.  Running the client produces the following:  Any help would be
greatly appreciated.

--run--
C:\home\developer\distinct>python pycal.py
connect: (127.0.0.1, 8888)
send: 'POST cal-server HTTP/1.0\r\n'
send: 'Host: 127.0.0.1\r\n'
send: 'Content-Type: text/plain; charset="utf-8"\r\n'
send: 'Content-Lenget: 514\r\n'
send: 'SOAPAction: http://uche.ogbuji.net/eg/ws/simple-cal\r\n'
send: '\r\n'
send: '<SOAP-ENV:Envelope\n
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env
elope/"\n  xmlns:s="http://uche.ogbuji.net/eg/ws/simple-cal"\n
xmlns:xsi="http:
//www.w3.org/1999/XMLSchema-instance"\n
xmlns:xsd"http://www.w3.org/1999/XMLSch
ema"\n
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">\n
 <SOAP-ENV:Body>\n        <s:getMonth>\n            <year
xsi:type="xsd:integer"
>2001</year>\n            <month xsi:type="xsd:integer">12</month>\n
</s:
getMonth>\n    </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>'
reply: 'HTTP/1.0 500 Internal error\r\n'
header: Server: <a href="http://www.actzero.com/solution.html">SOAP.py
0.9.7</a>
 (Python 2.2a2+)
header: Date: Wed, 15 May 2002 19:48:16 GMT
Traceback (most recent call last):
  File "pycal.py", line 43, in ?
    GetMonth()
  File "pycal.py", line 36, in GetMonth
    reply_body = requestor.getfile().read()
  File "c:\python22\lib\socket.py", line 229, in read
    new = self._sock.recv(k)
socket.error: (10054, 'Connection reset by peer')

--server code--
import sys, calendar

#Import the SOAP.py machinery
from WebServices import SOAP

CAL_NS = "http://uche.ogbuji.net/eg/ws/simple-cal"

class Calendar:
  def getMonth(self, year, month):
    return calendar.month(year, month)

  def getYear(self, year):
    return calendar.calendar(year)


server = SOAP.SOAPServer(("localhost", 8888))
cal = Calendar()
server.registerObject(cal, CAL_NS)

print "Starting server..."
server.serve_forever()

--client code--
 import sys, httplib

SERVER_ADDR = "127.0.0.1"
SERVER_PORT = 8888
CAL_NS = "http://uche.ogbuji.net/ws/eg/simple-cal"

BODY_TEMPLATE = """<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:s="http://uche.ogbuji.net/eg/ws/simple-cal"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
  <SOAP-ENV:Body>
    <s:getMonth>
      <year xsi:type="xsd:integer">%s</year>
      <month xsi:type="xsd:integer">%s</month>
    </s:getMonth>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""


def GetMonth():
    year = 2001
    month = 12
    body = BODY_TEMPLATE%(year, month)
    blen = len(body)
    requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT)
    requestor.putrequest("POST", "cal-server")
    requestor.putheader("Host", SERVER_ADDR)
    requestor.putheader("Content-Type", "text/plain; charset="utf-8"")
    requestor.putheader("Content-Length", str(blen))
    requestor.putheader("SOAPAction",
"http://uche.ogbuji.net/eg/ws/simple-car")
    requestor.endheaders()
    requestor.send(body)
    (status_code, message, reply_headers) = requestor.getreply()
    reply_body = requestor.getfile().read()

    print "status code:", status_code
    print "status message:", message
    print "HTTP reply body:\n", reply_body


if __name__ == "__main__":
    GetMonth()










More information about the Python-list mailing list