Proposed patch for #2589 to guard against content spoofing.

http://trac.buildbot.net/ticket/2589
A more specific exception -- `ValueError` -- would be better here.