Open stephlocke opened 5 years ago
The user agent seems to be passed correctly. The request is however forbidden.
resp$status_http()
<Status code: 403>
Message: Forbidden
Explanation: Request forbidden -- authorization will not help
In the API docs the only reason given for a 403 error is a missing user agent. https://haveibeenpwned.com/API/v2
We passe the User Agent in a list e.g.
list(`api-version` = "2"
, `User-Agent` = agent)
#> Error in eval(expr, envir, enclos): object 'agent' not found
Created on 2019-01-22 by the reprex package (v0.2.1)
And then this is how we pass it to crul
, as headers
crul::HttpClient$new(url = url,
headers = headers)$get()
Oh but now the Travis build no longer fails?!
Locally I still get the failures. :thinking:
@stephlocke we can rule out crul
being the issue
account <- "maelle.salmon@yahoo.se"
encoded <- urltools::url_encode(account)
URL <- paste0( # nolint
"https://haveibeenpwned.com/api/v2/breachedaccount/"
, encoded
)
headers <- list(`api-version` = "2",
`User-Agent` = "R package HIBPwned")
res <- crul::HttpClient$new(url = URL,
headers = headers)$get()
res$request_headers
#> $`Accept-Encoding`
#> [1] "gzip, deflate"
#>
#> $Accept
#> [1] "application/json, text/xml, application/xml, */*"
#>
#> $`api-version`
#> [1] "2"
#>
#> $`User-Agent`
#> [1] "R package HIBPwned"
httr::GET(URL,
httr::user_agent("R package HIBPwned"))
#> Response [https://haveibeenpwned.com/api/v2/breachedaccount/maelle.salmon%40yahoo.se]
#> Date: 2019-01-28 15:59
#> Status: 403
#> Content-Type: text/html; charset=UTF-8
#> Size: 1.96 kB
#> <!DOCTYPE html>
#> <head>
#> <title>Request Blocked</title>
#> <meta charset="UTF-8" />
#> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
#> </head>
#> <body>
#> <h1>You have been blocked from accessing this resource on Have I Been Pw...
#>
#> <p>This may be due to violating one or more of <a href="https://haveibee...
#> ...
Created on 2019-01-28 by the reprex package (v0.2.1)
Hypotheses:
Note that the build passes on Travis.
Possibly related https://github.com/michenriksen/hibp/issues/3
In the thread above folks write that they had to contact Troy Hunt to get their IP unblocked. :thinking:
@stephlocke if CRAN's IP was blocked by our tests, it's quite bad for #35
Besides, if we contacted the API maintainer, I wonder whether we could ask whether there was a reason in all the 403 errors/IP blocking. Bad luck for us or did we do something wrong?
For info now the tests pass on Travis. :woman_shrugging: