ctangent
asked on
Problem with calling webservice from python CGI in Tomcat
My program is:
#!c:\python24\python -u
from SOAPpy import WSDL
def header():
print "Content-type: text/html"
print
print "<HTML><HEAD>"
print "<TITLE>CGI Test</TITLE>"
print "</HEAD>"
print "<BODY>"
def footer():
print "</BODY></HTML>"
if __name__ == "__main__":
header()
wsdlFile = 'http://localhost/axis/services/DateService?wsdl'
service = WSDL.Proxy(wsdlFile)
out = service.getCurrentTimeMill is()
print '<h6>'
print out
print '</h6>'
footer()
When run from the command prompt, it succeeds with the output being:
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
<?HEAD>
<BODY>
<h6>
1143129399317
</h6>
</BODY></HTML>
However, when I run the cgi through tomcat by typing the command into the web browser:
http://localhost/testcount-gui/cgi-bin/date.cgi
I get this as a response (after right-click, view source):
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
</HEAD>
<BODY>
It fails at this call:
service = WSDL.Proxy(wsdlFile)
In the Tomcat logs, the only logfile updated is the log that says:
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr):Traceback (most recent call last):
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Tomcat 5.5\webapps\testcount-gui\ WEB-INF\cg i\date.cgi ", line 26, in ?
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\SOAPp y\WSDL.py" , line 67, in __init__
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): self.wsdl = reader.loadFromString(str( wsdlsource ))
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\SOAPp y\wstools\ WSDLTools. py", line 47, in loadFromString
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): return self.loadFromStream(String IO(data))
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\SOAPp y\wstools\ WSDLTools. py", line 28, in loadFromStream
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): document = DOM.loadDocument(stream)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\SOAPp y\wstools\ Utility.py ", line 602, in loadDocument
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): return xml.dom.minidom.parse(data )
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\_xmlp lus\dom\mi nidom.py", line 1915, in parse
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): return expatbuilder.parse(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\_xmlp lus\dom\ex patbuilder .py", line 930, in parse
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): result = builder.parseFile(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\_xmlp lus\dom\ex patbuilder .py", line 207, in parseFile
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): parser.Parse(buffer, 0)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr):xml.parsers.expat .ExpatErro r: not well-formed (invalid token): line 1, column 5
So the error is: xml.parsers.expat.ExpatErr or: not well-formed (invalid token)
I think it is weird that this works outside of running through Tomcat. My only thought is that its a permissions issue in Windows, except my Tomcat installation is in C:\Tomcat5\ so this shouldn't be a problem, and my Python installation is C:\Python24\.
Any ideas on what could be causing this problem?
#!c:\python24\python -u
from SOAPpy import WSDL
def header():
print "Content-type: text/html"
print "<HTML><HEAD>"
print "<TITLE>CGI Test</TITLE>"
print "</HEAD>"
print "<BODY>"
def footer():
print "</BODY></HTML>"
if __name__ == "__main__":
header()
wsdlFile = 'http://localhost/axis/services/DateService?wsdl'
service = WSDL.Proxy(wsdlFile)
out = service.getCurrentTimeMill
print '<h6>'
print out
print '</h6>'
footer()
When run from the command prompt, it succeeds with the output being:
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
<?HEAD>
<BODY>
<h6>
1143129399317
</h6>
</BODY></HTML>
However, when I run the cgi through tomcat by typing the command into the web browser:
http://localhost/testcount-gui/cgi-bin/date.cgi
I get this as a response (after right-click, view source):
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
</HEAD>
<BODY>
It fails at this call:
service = WSDL.Proxy(wsdlFile)
In the Tomcat logs, the only logfile updated is the log that says:
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr):Traceback (most recent call last):
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Tomcat 5.5\webapps\testcount-gui\
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): self.wsdl = reader.loadFromString(str(
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): return self.loadFromStream(String
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): document = DOM.loadDocument(stream)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): return xml.dom.minidom.parse(data
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): return expatbuilder.parse(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): result = builder.parseFile(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): parser.Parse(buffer, 0)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr):xml.parsers.expat
So the error is: xml.parsers.expat.ExpatErr
I think it is weird that this works outside of running through Tomcat. My only thought is that its a permissions issue in Windows, except my Tomcat installation is in C:\Tomcat5\ so this shouldn't be a problem, and my Python installation is C:\Python24\.
Any ideas on what could be causing this problem?
ASKER
Yes. If I run the cgi program through the command line (python date.cgi) it works, which means that SOAPpy is actually taking the WSDL file and creating the Proxy, and then I can use it successfully. The code also works if I type in the commands into the Python interpreter. The cgi script fails when I run it through the cgi call on Tomcat, so thats the only difference. To me it has to be either a permissions issue or a python module is not being accessed by Tomcat, but I don't know how to fix it.
Neither, you can see it from traceback. Please answer _my_ question.
ASKER
"Do you get a well formed wsdl file?"
Yes, as mentioned in my first response.
"What do you get when you type the command into the web browser:
http://localhost/axis/services/DateService?wsdl"
Sorry, I thought the reql question was "Do you get a well formed wsdl file?"
What do you mean by "Neither, you can see it from traceback"? Here is the wsdl file below, as shows up when http://localhost/axis/services/DateService?wsdl is typed into the browser:
<wsdl:definitions targetNamespace="urn:Test1 ">
<!--
WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
-->
<wsdl:message name="getCurrentTimeMillis Request">
</wsdl:message>
<wsdl:message name="getDateResponse">
<wsdl:part name="getDateReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="getDateRequest">
</wsdl:message>
<wsdl:message name="getCurrentTimeMillis Response">
<wsdl:part name="getCurrentTimeMillis Return" type="soapenc:string"/>
</wsdl:message>
<wsdl:portType name="DateService">
<wsdl:operation name="getCurrentTimeMillis ">
<wsdl:input message="impl:getCurrentTi meMillisRe quest" name="getCurrentTimeMillis Request"/>
<wsdl:output message="impl:getCurrentTi meMillisRe sponse" name="getCurrentTimeMillis Response"/ >
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdl:input message="impl:getDateReque st" name="getDateRequest"/>
<wsdl:output message="impl:getDateRespo nse" name="getDateResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DateServiceSoapBindi ng" type="impl:DateService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getCurrentTimeMillis ">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getCurrentTimeMillis Request">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getCurrentTimeMillis Response">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getDateRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getDateResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DateServiceService">
<wsdl:port binding="impl:DateServiceS oapBinding " name="DateService">
<wsdlsoap:address location="http://localhost/axis/services/DateService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Yes, as mentioned in my first response.
"What do you get when you type the command into the web browser:
http://localhost/axis/services/DateService?wsdl"
Sorry, I thought the reql question was "Do you get a well formed wsdl file?"
What do you mean by "Neither, you can see it from traceback"? Here is the wsdl file below, as shows up when http://localhost/axis/services/DateService?wsdl is typed into the browser:
<wsdl:definitions targetNamespace="urn:Test1
<!--
WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
-->
<wsdl:message name="getCurrentTimeMillis
</wsdl:message>
<wsdl:message name="getDateResponse">
<wsdl:part name="getDateReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="getDateRequest">
</wsdl:message>
<wsdl:message name="getCurrentTimeMillis
<wsdl:part name="getCurrentTimeMillis
</wsdl:message>
<wsdl:portType name="DateService">
<wsdl:operation name="getCurrentTimeMillis
<wsdl:input message="impl:getCurrentTi
<wsdl:output message="impl:getCurrentTi
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdl:input message="impl:getDateReque
<wsdl:output message="impl:getDateRespo
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DateServiceSoapBindi
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getCurrentTimeMillis
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getCurrentTimeMillis
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getCurrentTimeMillis
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getDateRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:input>
<wsdl:output name="getDateResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DateServiceService">
<wsdl:port binding="impl:DateServiceS
<wsdlsoap:address location="http://localhost/axis/services/DateService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
>>To me it has to be either a permissions issue or a python module is not being accessed by Tomcat, but I don't know how to fix it.
> Neither, you can see it from traceback
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack ages\SOAPp y\WSDL.py" , line 67, in __init__
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A pplication Context log
INFO: cgi: runCGI (stderr): self.wsdl = reader.loadFromString(str( wsdlsource ))
As you can see your script was called OK and it calls WSDL.py OK as well.
Permissions it can be but write perm for temp file or something similar.
Check wsdl source (in brouser as well - "View source"), provide first 3 lines here please.
> Neither, you can see it from traceback
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): File "C:\Python24\Lib\site-pack
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.A
INFO: cgi: runCGI (stderr): self.wsdl = reader.loadFromString(str(
As you can see your script was called OK and it calls WSDL.py OK as well.
Permissions it can be but write perm for temp file or something similar.
Check wsdl source (in brouser as well - "View source"), provide first 3 lines here please.
ASKER
From "view source" after http://localhost/axis/services/DateService?wsdl typed into browser:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:Test1 " xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:Test1" xmlns:intf="urn:Test1" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:message name="getCurrentTimeMillis Request">
</wsdl:message>
Okay, a little more than first few lines, but you can see that it continues after this to what I displayed in the previous post. What is so wierd is that there is no error when I run the program by the command line; it works great then.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:Test1
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:message name="getCurrentTimeMillis
</wsdl:message>
Okay, a little more than first few lines, but you can see that it continues after this to what I displayed in the previous post. What is so wierd is that there is no error when I run the program by the command line; it works great then.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
expat? The XML parser, or something else?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Any suggestions on how to get this information when I run the command line?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
mish33,
Thank you for your help. It will be a few days before I can get back to this, but when I do I will post.
Thank you for your help. It will be a few days before I can get back to this, but when I do I will post.
ASKER
Venabili,
Apologies. The problem was not easily solved, the only solution suggested invovling alot more work and time than I had. Meanwhile, I found another route to take in my work that avoided the problem alltogether. Thus, this question has been hanging over my head for sometime, not sure what to do.
If I run across the same problem in the future, however, I will know where to begin in solving the problem (mish33 writes: Aparently execution context is not the same. Please check which expat is loaded in either case (command-line and apache), I suspect they aren't the same.)
I'd like to give him full points for this, with the suggestion to check the expat and how to do this as an assisted answer.
Let me know what you think.
Apologies. The problem was not easily solved, the only solution suggested invovling alot more work and time than I had. Meanwhile, I found another route to take in my work that avoided the problem alltogether. Thus, this question has been hanging over my head for sometime, not sure what to do.
If I run across the same problem in the future, however, I will know where to begin in solving the problem (mish33 writes: Aparently execution context is not the same. Please check which expat is loaded in either case (command-line and apache), I suspect they aren't the same.)
I'd like to give him full points for this, with the suggestion to check the expat and how to do this as an assisted answer.
Let me know what you think.
ASKER
mish33,
Thank you for your support in helping find a solution to this problem. Since I ran out of time to actually solve the problem, I will accept the possiblity of the XML expat being different, and the fact that the cgi was running in two different contexts.
-- ctangent
Thank you for your support in helping find a solution to this problem. Since I ran out of time to actually solve the problem, I will accept the possiblity of the XML expat being different, and the fact that the cgi was running in two different contexts.
-- ctangent
Any time
http://localhost/axis/services/DateService?wsdl
Do you get a well formed wsdl file?