MySQLPageGenerator says it can take a 'site' argument as either a Site object or a string (that represents the dbname). If 'site' isn't given, it defaults to the current Site.
In all cases, site ends up being a string, either because that's what was passed as an argument, or because the Site object is replaced by the dbname in 'site = site.dbName()'
However, a few lines later, site is expected to be a Site object again in 'query = query.encode(site.encoding())'.
This throws an AttributeError: 'unicode' object has no attribute 'encoding'.