From 00eee3fc136c8d383f0236d2e67e2d0e595edde5 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Mon, 8 Apr 2019 12:03:48 +0200 Subject: [PATCH 01/11] Fix panic: interface conversion: interface {} is nil, not map[string]interface {} --- anticaptcha.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/anticaptcha.go b/anticaptcha.go index 80ac493..ace72ec 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "time" + "github.com/pkg/errors" ) var ( @@ -104,6 +105,10 @@ func (c *Client) SendRecaptcha(websiteURL string, recaptchaKey string) (string, break } } + + if response == nil { + return "", errors.Errorf("Failed to get a response") + } return response["solution"].(map[string]interface{})["gRecaptchaResponse"].(string), nil } From 479b2c51f99524a1737e6e220d5e5345c5a54e1e Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Mon, 8 Apr 2019 12:20:16 +0200 Subject: [PATCH 02/11] format --- anticaptcha.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anticaptcha.go b/anticaptcha.go index ace72ec..8ff6d53 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -3,11 +3,11 @@ package anticaptcha import ( "bytes" "encoding/json" + "github.com/pkg/errors" "log" "net/http" "net/url" "time" - "github.com/pkg/errors" ) var ( @@ -105,7 +105,7 @@ func (c *Client) SendRecaptcha(websiteURL string, recaptchaKey string) (string, break } } - + if response == nil { return "", errors.Errorf("Failed to get a response") } From de8520eca0dad8252d1283144dff77ccde7f610d Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Wed, 10 Apr 2019 05:50:09 +0200 Subject: [PATCH 03/11] Update anticaptcha.go --- anticaptcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anticaptcha.go b/anticaptcha.go index 8ff6d53..4b07568 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -106,7 +106,7 @@ func (c *Client) SendRecaptcha(websiteURL string, recaptchaKey string) (string, } } - if response == nil { + if response["solution"] == nil { return "", errors.Errorf("Failed to get a response") } return response["solution"].(map[string]interface{})["gRecaptchaResponse"].(string), nil From 7f30983cb4f7ae312f805ad719afcf83a1797b3c Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Fri, 12 Apr 2019 21:38:51 +0200 Subject: [PATCH 04/11] handle more nil reponses --- anticaptcha.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/anticaptcha.go b/anticaptcha.go index 4b07568..5a46be6 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -48,6 +48,9 @@ func (c *Client) createTaskRecaptcha(websiteURL string, recaptchaKey string) (fl responseBody := make(map[string]interface{}) json.NewDecoder(resp.Body).Decode(&responseBody) // TODO treat api errors and handle them properly + if responseBody["taskId"] == nil { + return 0, errors.Errorf("Failed to get a response") + } return responseBody["taskId"].(float64), nil } From 49186ff12389746889dcc3e7f133826f26194b46 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:39:35 +0200 Subject: [PATCH 05/11] handle errors --- anticaptcha.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/anticaptcha.go b/anticaptcha.go index 5a46be6..5052ba5 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -142,6 +142,9 @@ func (c *Client) createTaskImage(imgString string) (float64, error) { // Decode response responseBody := make(map[string]interface{}) json.NewDecoder(resp.Body).Decode(&responseBody) + if response["taskId"] == nil { + return "", errors.Errorf("Failed to get a response") + } // TODO treat api errors and handle them properly return responseBody["taskId"].(float64), nil } From 7f8e0d7d56f48ec382e744259581319e135f6de0 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:39:50 +0200 Subject: [PATCH 06/11] Update anticaptcha.go --- anticaptcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anticaptcha.go b/anticaptcha.go index 5052ba5..5d4f4ec 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -3,7 +3,7 @@ package anticaptcha import ( "bytes" "encoding/json" - "github.com/pkg/errors" + "errors" "log" "net/http" "net/url" From 3a86af52b822ba4d1ba7864150d373f4d39b298f Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:41:46 +0200 Subject: [PATCH 07/11] Update anticaptcha.go --- anticaptcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anticaptcha.go b/anticaptcha.go index 5d4f4ec..5052ba5 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -3,7 +3,7 @@ package anticaptcha import ( "bytes" "encoding/json" - "errors" + "github.com/pkg/errors" "log" "net/http" "net/url" From 4ec23303f8c2a6e1b82165c307aafbb9837ad906 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:43:50 +0200 Subject: [PATCH 08/11] Update anticaptcha.go --- anticaptcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anticaptcha.go b/anticaptcha.go index 5052ba5..c275bcf 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -142,7 +142,7 @@ func (c *Client) createTaskImage(imgString string) (float64, error) { // Decode response responseBody := make(map[string]interface{}) json.NewDecoder(resp.Body).Decode(&responseBody) - if response["taskId"] == nil { + if responseBody["taskId"] == nil { return "", errors.Errorf("Failed to get a response") } // TODO treat api errors and handle them properly From d0d836ba6cad09883ecf84add1adb8424b965b82 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:49:36 +0200 Subject: [PATCH 09/11] Update anticaptcha.go --- anticaptcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anticaptcha.go b/anticaptcha.go index c275bcf..9310a26 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -142,7 +142,7 @@ func (c *Client) createTaskImage(imgString string) (float64, error) { // Decode response responseBody := make(map[string]interface{}) json.NewDecoder(resp.Body).Decode(&responseBody) - if responseBody["taskId"] == nil { + if reflect.ValueOf(responseBody["taskId"]).IsNil() { return "", errors.Errorf("Failed to get a response") } // TODO treat api errors and handle them properly From 62f39b69f6ca4a724dfcaaf863a450ff5b31b073 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:50:30 +0200 Subject: [PATCH 10/11] Update anticaptcha.go --- anticaptcha.go | 1 + 1 file changed, 1 insertion(+) diff --git a/anticaptcha.go b/anticaptcha.go index 9310a26..ddc50dd 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "time" + "reflect" ) var ( From da8a21085d18f67a39589a6ae098a2dd5f9166cf Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Sun, 13 Oct 2019 11:52:09 +0200 Subject: [PATCH 11/11] Update anticaptcha.go --- anticaptcha.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anticaptcha.go b/anticaptcha.go index ddc50dd..4c33d8a 100644 --- a/anticaptcha.go +++ b/anticaptcha.go @@ -49,8 +49,8 @@ func (c *Client) createTaskRecaptcha(websiteURL string, recaptchaKey string) (fl responseBody := make(map[string]interface{}) json.NewDecoder(resp.Body).Decode(&responseBody) // TODO treat api errors and handle them properly - if responseBody["taskId"] == nil { - return 0, errors.Errorf("Failed to get a response") + if reflect.ValueOf(responseBody["taskId"]).IsNil() { + return "", errors.Errorf("Failed to get a response") } return responseBody["taskId"].(float64), nil }