I have a Spring 3 web service that serves up some data. It works perfectly from Firefox, but when I tried to access it via a simple Python script using urllib2, I consistently get back HTTP 404.
This happens whether or not I am running my web service via Tomcat under Eclipse, or Tomcat running as a Windows service.
The only thing I can think of (which still doesn't seem likely) is that something about the web service (under the hood) is unhappy about the urllib2 user agents string...
Can anyone give me some ideas about what to try next?
Thanks,
Mitch
Here is a simplified version of the code, followed by the screen output:
import sys
import urllib2
import urllib
import datetime
import time
import httplib
from datetime import timedelta
url = 'http://localhost:8086/OamDataWebService/oamdatawebservice/oamdata5 /SYRC01TAMP20/1334127600000/1334131199000'
handler=urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
req = urllib2.Request(url=url)
req.add_header('Content-Type', 'text/xml')
try:
resp = urllib2.urlopen(req)
except urllib2.HTTPError, e:
print "ERROR: caught HTTPError exception"
print "HTTP error code:", e.code
print e.read()
sys.exit(1)
content = resp.read()
print content
$ python test.py send: 'GET /OamDataWebService/oamdatawebservice/oamdata5/SYRC01TAMP20/1334127600000/1334131199000 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: tbdivb2400 2.corp.local:8086\r\nContent-Type: text/xml\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n' reply: 'HTTP/1.1 404 Not Found\r\n' header: Server: Apache-Coyote/1.1 header: Content-Type: text/html;charset=utf-8 header: Content-Length: 952 header: Date: Fri, 13 Apr 2012 13:56:28 GMT header: Connection: close ERROR: caught HTTPError exception HTTP error code: 404 Apache Tomcat/6.0.35 - Error report
HTTP Status 404 -
type Status report
message
description The requested resource () is not available.
Apache Tomcat/6.0 .35
I think the problem is in my Spring Controller configuration, but I still don't understand why it works so consistently one way and not from Python. I am running now from Chrome,and I believe I am sending the same thing.
My Tomcat logs show the following when I send the request via urllib:
2012-04-13 14:31:26,782 WARN org.springframework.web.servlet.PageNotFound.handleNoSuchRequestHandlingMethod:142 - No matching handler method found for servlet request: path '/oamdata5/SYRC01TAMP20/1334127600000/1334131199000', method 'GET', parameters map[[empty]]
My Spring web.xml servlet mapping is:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
And my RequestMapping entry is:
@RequestMapping(value = "/{interval}/{serviceId}/{startTime}/{endTime}",
method = RequestMethod.GET,
headers="Accept=application/xml, application/json")