From: Gwyn E. <gw...@jd...> - 2003-10-21 10:07:25
|
Hi, This is primarily for the record, though being new to Jython/Python, I'd be interested in any comments anyone has with respect to development & debugging environments/techniques... I was just developing a basic test using jython, as shown below, when I started having problems! import unittest import httplib class ExampleTest(unittest.TestCase): def setUp(self): self.host = "localhost" self.port = '7001' self.httpConnection = httplib.HTTPConnection(self.host, self.port) def runTest(self): self.httpConnection.request("GET", "/") response = self.httpConnection.getresponse() text = response.read() self.assertEqual(text, "OK\r\n") if __name__ == "__main__": runner = unittest.TextTestRunner() runner.run(ExampleTest()) When I ran this through Python I had no problems, but as I intended to try & capture the message that the server posted to a JMS queue, I wanted to run this under Jython, but that gave me traceback, as follows... Traceback (most recent call last): File "ExampleTest.py", line 14, in runTest self.httpConnection.request("GET", "/") File "D:\Java\Jython\Lib\httplib.py", line 508, in request self._send_request(method, url, body, headers) File "D:\Java\Jython\Lib\httplib.py", line 517, in _send_request self.putrequest(method, url) File "D:\Java\Jython\Lib\httplib.py", line 437, in putrequest self.send(str) File "D:\Java\Jython\Lib\httplib.py", line 379, in send self.connect() File "D:\Java\Jython\Lib\httplib.py", line 363, in connect self.sock.connect((self.host, self.port)) File "D:\Java\Jython\Lib\socket.py", line 135, in connect self._setup(java.net.Socket(host, port)) TypeError: java.net.Socket(): 1st arg can't be coerced to String or java.net.InetAddress I had a hunt around for any easy way of debugging the Jython code, but ended up having to just add print statements to try & see what was going on... Tried creating by hand the 'host' as a java.lang.String, to no effect, and was starting to wonder if there was any way I could use Python to read JMS messages when I noticed in the socket.py that if the 'host' was "", then the code itself got the localhost address, so I tried that. That then made things much clearer, as the new error message was "TypeError: java.net.Socket(): 2nd arg can't be coerced to int". As soon as I changed my "self.port = '7001'" to "self.port = 7001" then all was well and I could get on with developing the rest of the test... -- Best regards, Gwyn mailto:gw...@jd... |