use localhost instead of 127.0.0.1
remove the stray ```
use tempfile instead of tmp, tmp2, and tmp3