From 2e23df42524c8db4dc47e8f78bf5fe6fe0608b5b Mon Sep 17 00:00:00 2001 From: Adrian Kumpf <8999358+adriankumpf@users.noreply.github.com> Date: Thu, 8 Jul 2021 12:15:25 +0200 Subject: [PATCH] Fix login for Chinese accounts --- lib/tesla_api/auth.ex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/tesla_api/auth.ex b/lib/tesla_api/auth.ex index 3a1f395f83..004c33e1cb 100644 --- a/lib/tesla_api/auth.ex +++ b/lib/tesla_api/auth.ex @@ -100,16 +100,17 @@ defmodule TeslaApi.Auth do params = Keyword.put(params, :login_hint, email) case load_form(params, cookies) do - {:ok, {form, _captcha, cookies, base_url}} -> + {:ok, {form, captcha, cookies, base_url}} -> form = form |> Map.replace!("identity", email) |> Map.replace!("credential", password) form = - case captcha_code do - nil -> form - code -> Map.replace!(form, "captcha", code) + if captcha == nil or captcha_code == nil do + form + else + Map.replace!(form, "captcha", captcha_code) end with {:ok, %Tesla.Env{} = env} <-