Python Write Error Too Many Redirects