Whether your landlord is too much of a stickler or not enough of one, nobody wants to be stuck at odds with the person who manages the roof over your head. Reading the lease carefully and looking out for warning signs can help you avoid this situation, but once you are in the situation, there are still things you can do.
Document Everything
The number one rule of any situation where it could come down to "he said/she said" in court is to document everything. Communicate in email or text when possible. Keep copies of everything. If you have phone conversations, note what was said when, and what agreements were made. Keep track of repairs that were and weren't completed. Take photographs. The best way to protect yourself is to document the facts.
Communicate Clearly
People have different communication styles, and sometimes those styles conflict with each other. Since you're already communicating with your landlord in writing, take a minute to look things over. Have you communicated the extent of your need? Maybe a faucet is leaking, but the landlord doesn't understand that the water is collecting and threatening to damage the surrounding fixtures. Sometimes it's a question of them understanding the urgency of the situation - landlords generally have a lot to deal with.
Pay Rent
Really, be a model tenant in general. You don't want to give the landlord reasons not to like you. If you can't resolve your conflict peacefully and the situation does go to court, any words spoken in anger or untoward behavior on your part will be the first thing the landlord pulls out in their defense. Pay your rent on time, and conduct yourself in such a way that if worse comes to worse, they don't have anything that could be used against you.
Know Your Lease
Maybe the landlord is charging fees that aren't stipulated in the lease or is trying to get rid of a pet after signing an agreement that you could have one. Whatever the case may be, this document governs your relationship, and it's there to protect you as much as it protects them. Know clearly what your rights are and aren't, as opposed to what you do or don't think is "fair." Referring to the lease is the fastest way to get most landlords to change their behavior.
Know the Law
Laws governing landlord-lessee agreements vary from state to state and knowing what they are is important. Here are some big ones, though: For starters, the landlord is allowed access to the property, with proper notice, during reasonable hours. But they are not allowed to violate your right to privacy. While you cannot change locks (that counts as tampering with the structure of the house) in many cases you can add locks to ensure your privacy. You must receive prior notice, usually a minimum of two weeks, before you can be evicted. If you have a careless, irresponsible, or threatening landlord, the odds are that they either won't know your rights, or they'll be counting on you not to know them in order to bully you. Don't let that happen.
Go to the Next Level
When all else fails, you should file a complaint with the state or file a civil suit. This should be the absolute last resort, and it should only be done after careful study of the laws in your state and consultation with a landlord-tenant lawyer. If the landlord is clearly violating the lease or the law, you may have no other choice. If there's any way to reach a peaceful solution, do that. If not, this is where everything you've done so far - from the documentation to the research - comes together to help you out.