When any tax on real property is paid by or collected of any occupant or tenant, or any other person, which, by agreement or otherwise, ought to have been paid by the owner, lessor, or other party in interest, such occupant, tenant, or other person may recover by action the amount which such owner, lessor, or party in interest ought to have paid, with interest thereon at the rate of ten percent per annum, or he or she may retain the same from any rent due or accruing from him or her to such owner or lessor for real property on which such tax is so paid; and the same shall, until paid, constitute a lien upon such real property.