std/uti

is it safe or okay to take pills to treat an std or uti w. out it being prescribed to you , like can i just visit cvs or walmart and treatments?