title: urllib2 returns HTTP 404 from web service that is up
body: <p>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.</p>
  
  <p>This happens whether or not I am running my web service via Tomcat under Eclipse, or Tomcat running as a Windows service.</p>
  
  <p>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... </p>
  
  <p>Can anyone give me some ideas about what to try next?</p>
  
  <p>Thanks,</p>
  
  <p>Mitch</p>
  
  <p>Here is a simplified version of the code, followed by the screen output:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>$ 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 <h1>HTTP Status 404 - </h1><p><b>type</b> Status report</p>
  
  <blockquote>
    <p><b>message</b> </p><p><b>description</b> The requested resource () is not available.</p><h3>Apache Tomcat/6.0
    .35</h3></p>
  </blockquote>
  
  <p>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.</p>
  
  <p>My Tomcat logs show the following when I send the request via urllib:</p>
  
  <p>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]]</p>
  
  <p>My Spring web.xml servlet mapping is:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>And my RequestMapping entry is:</p>
  
  <pre><code>@RequestMapping(value = "/{interval}/{serviceId}/{startTime}/{endTime}", 
      method = RequestMethod.GET, 
      headers="Accept=application/xml, application/json")
  </code></pre>