MarkEdmondson1234 / searchConsoleR

R interface with Google Search Console API v3, including Search Analytics.
http://code.markedmondson.me/searchConsoleR/
Other
114 stars 41 forks source link

Error fix_sample_url with URL encoded Umlauts #36

Closed netzstreuner closed 6 years ago

netzstreuner commented 6 years ago

Hi,

I have the following URL/path I'd like to mark as fixed de/k%C3%B6ln/koeln-dom/.

fix_sample_url(siteURL = "http://XXXXXX", 
    category = "notFound",
    pageURL = "de/k%C3%B6ln/koeln-dom/", 
    platform = "web")

I get the following error message:

Request failed [404]. Retrying in 1 seconds...
Request failed [404]. Retrying in 3.1 seconds...
2018-01-15 17:35:00> Request Status Code: 404
Error : lexical error: invalid char in json text.
                                       Not Found
                     (right here) ------^

Error: lexical error: invalid char in json text.
                                       Not Found
                     (right here) ------^
In addition: Warning message:
No JSON content found in request

fix_sample_url works just fine with every other URL, that has no URL encoded Umlauts.

Am I doing something wrong?

Cheers,

Patrick

MarkEdmondson1234 commented 6 years ago

Hmm not sure if this is an API or this R implementation issue, but the error suggests the pageURL isn't present in your list to fix. You may want to set options(googleAuthR.verbose = 2) and do the call again and inspect what is sent to see if that gives any clues. You could also try encoding the whole URL, using URLencode("de/theurltoencode/")

netzstreuner commented 6 years ago

Hi Mark, thanks for your quick reply.

I set options(googleAuthR.verbose = 2) and it turns out that the URL is incorrectly encoded.

Incorrectly encoded URL with umlauts (the slashes are not encoded):

https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.XXXXX%2F/urlCrawlErrorsSamples/de/k%C3%B6ln/koeln-dom/?category=notFound&platform=web

Correctly encoded URL without umlauts:

https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.XXXXX%2F/urlCrawlErrorsSamples/hu%2Fma%2F?category=notFound&platform=web

After using urltools::url_encode the URL is correctly encoded and can be marked as fixed:

> fix_sample_url(siteURL = "http://www.XXXXX/", 
+                category = "notFound",
+                pageURL = url_encode("de/k%C3%B6ln/koeln-dom/"), 
+                platform = "web")
2018-01-16 09:38:57> Token exists.
2018-01-16 09:38:57> Request: https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.XXXXX%2F/urlCrawlErrorsSamples/de%2fk%25C3%25B6ln%2fkoeln-dom%2f?category=notFound&platform=web
[1] TRUE

Thanks again for your help!

MarkEdmondson1234 commented 6 years ago

Great, glad it helped.