michenriksen / hibp

A simple tool to check a bunch of email addresses against the Have I Been Pwned API.
https://rubygems.org/gems/hibp
MIT License
64 stars 20 forks source link

HTTP Error 403 #3

Open thehappydinoa opened 5 years ago

thehappydinoa commented 5 years ago

I am currently getting this error from hibp -f info.txt: Hibp::HttpClient::ClientError: GET to https://haveibeenpwned.com/api/breachedaccount/<email> returned status 403 - options: {:query=>nil}

ghost commented 5 years ago

Same, not sure what is wrong

Fortesqueu commented 5 years ago

Same here!

Fortesqueu commented 5 years ago

403 | Forbidden — no user agent has been specified in the request

(from API documentation) I'd like to know how to specify a "user agent", any idea?

exhaustdad commented 5 years ago

Bummer. Just came across this too... No update or idea on how to avoid this?

cwanderley commented 5 years ago

Folks, everyone is getting 403 for the following reason: "Specifying the user agent Each request to the API must be accompanied by a user agent request header. Typically this should be the name of the app consuming the service. A missing user agent will result in an HTTP 403 response."

GET https://haveibeenpwned.com/api/{service}/{parameter} User-Agent: [your app name]

https://haveibeenpwned.com/API/v2#UserAgent

cwanderley commented 5 years ago

I've used the following code and worked well, any problem! $agent = array('http' => array('user_agent' => 'any code here')); //could be the initial letters of your name $curl = curl_init('https://haveibeenpwned.com/api/v2/breachedaccount/test@example); //Creates a new cURL resource curl_setopt($curl, CURLOPT_USERAGENT, $agent ); //Set URL options, CURLOPT_URL is the URL to fetch at $path curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //Set URL options, true to return transfer as a string $xmlResponse = curl_exec($curl); //Execute the given cURL session after options are set $info = curl_getinfo($curl); //Get information about the transfer curl_close($curl); //Close cURL resource

$hibp_result=json_decode($xmlResponse,true); //Convert a string to a PHP variable