Redirecting to a 200 response offline.html is a really bad idea for the API

Bug #504199 reported by James Westby
This bug report is a duplicate of:  Bug #475371: Redirection to offline.html on 503s. Edit Remove
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Launchpad itself
Triaged
Low
Unassigned
lazr.restful
Triaged
Low
Unassigned

Bug Description

Hi,

Using the API I sometimes see

  File "/usr/lib/python2.5/site-packages/launchpadlib/resource.py", line 446, in __getattr__
    return super(Entry, self).__getattr__(name)
  File "/usr/lib/python2.5/site-packages/launchpadlib/resource.py", line 283, in __getattr__
    return self.lp_get_parameter(attr)
  File "/usr/lib/python2.5/site-packages/launchpadlib/resource.py", line 185, in lp_get_parameter
    self._ensure_representation()
  File "/usr/lib/python2.5/site-packages/launchpadlib/resource.py", line 306, in _ensure_representation
    representation, self.JSON_MEDIA_TYPE)
  File "/usr/lib/python2.5/site-packages/wadllib/application.py", line 326, in bind
    representation_definition)
  File "/usr/lib/python2.5/site-packages/wadllib/application.py", line 263, in __init__
    self.representation = simplejson.loads(representation)
  File "/var/lib/python-support/python2.5/simplejson/__init__.py", line 262, in loads
    return _default_decoder.decode(s)
  File "/var/lib/python-support/python2.5/simplejson/decoder.py", line 251, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/var/lib/python-support/python2.5/simplejson/decoder.py", line 270, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Catching it in the act shows that it is actually sending

send: 'GET /beta/ubuntu/lucid HTTP/1.1\r\nHost: api.edge.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth [...]\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 302 Found\r\n'
header: Date: Thu, 07 Jan 2010 11:01:03 GMT
header: Cache-Control: no-cache
header: Location: /offline.html
header: Via: 1.1 wildcard.edge.launchpad.net
header: Transfer-Encoding: chunked
header: Content-Type: text/plain
send: 'GET /offline.html HTTP/1.1\r\nHost: api.edge.launchpad.net:443\r\nAccept-Encoding: identity\r\nAuthorization: OAuth [...]\r\nte: deflate, gzip\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 07 Jan 2010 11:01:53 GMT
header: Server: Apache/2.2.8 (Ubuntu) mod_ssl/2.2.8 OpenSSL/0.9.8g
header: Last-Modified: Mon, 22 Jun 2009 09:40:43 GMT
header: ETag: "1946dd-399-46cecaaf35cc0"
header: Accept-Ranges: bytes
header: Content-Length: 921
header: Content-Type: text/html

so launchpadlib dutifully tries to decode

'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n <head>\n <title>Please try again</title>\n <style type="text/css" media="screen, print">\n @import url(https://launchpad.net/+icing/rev5/+style-slimmer.css);\n </style>\n </head>\n <body>\n <div id="topline"></div>\n <div id="locationbar"></div>\n <div class="offline">\n\n <h1>Please try again</h1>\n <p>\n Sorry, there was a problem connecting to the Launchpad server.\n </p>\n <p>\n Try reloading this page in a minute or two.\n If the problem persists, let us know in\n <a href="irc://chat.freenode.net/#launchpad"\n >the #launchpad IRC channel on Freenode</a>.\n </p>\n <p>Thanks for your patience.</p>\n\n </div>\n </body>\n</html>\n'

as a representation of Ubuntu Lucid, which isn't going to work very well.

When LP is offline could you please not redirect webservice requests to offline.html?
I would suggest returning a 503 with the same contents in the body, or just making
offline.html return 503 (this would make sense for browser users too no?)

Thanks,

James

Related branches

Revision history for this message
James Westby (james-w) wrote :

Adding a lazr.restful task as trying to decode a Content-Type: text/html response
as JSON probably isn't the best thing to do. If it doesn't have a wadl representation
corresponding to that content type it should probably just throw an error that says
that. It would at least have made this problem easier to debug.

Thanks,

James

summary: - Redirecting to offline.html is a really bad idea for the API
+ Redirecting to a 200 response offline.html is a really bad idea for the
+ API
Revision history for this message
Stuart Bishop (stub) wrote :

The Launchpad end of this is Bug #475371.

Curtis Hovey (sinzui)
affects: launchpad → launchpad-foundations
Changed in launchpad-foundations:
importance: Undecided → Low
status: New → Triaged
Changed in lazr.restful:
importance: Undecided → Low
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.