ipinfo / rust

IPinfo Rust library for IPinfo API (IP geolocation and other types of IP data)
https://ipinfo.io
Apache License 2.0
56 stars 14 forks source link

missing field `hostname` in ipinfo.io response #12

Closed keroro520 closed 3 years ago

keroro520 commented 3 years ago

It seems that hostname is not included for the free accounts. The lookup function returns the below error which is caused by serde deserialization.

error: IpError { kind: ParseError, description: Some("missing field `hostname` at line 10 column 3") }

I use curl to make a request and the response does not contain hostname either.

curl http://ipinfo.io/47.89.252.15
{
  "ip": "47.89.252.15",
  "city": "Santa Clara",
  "region": "California",
  "country": "US",
  "loc": "37.3541,-121.9552",
  "org": "AS45102 Alibaba (US) Technology Co., Ltd.",
  "postal": "95052",
  "timezone": "America/Los_Angeles",
  "readme": "https://ipinfo.io/missingauth"
}
UmanShahzad commented 3 years ago

This is because hostname isn't always available for some IPs:

$ curl http://ipinfo.io/8.8.8.8
{
  "ip": "8.8.8.8",
  "hostname": "dns.google",
  "anycast": true,
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.4056,-122.0775",
  "org": "AS15169 Google LLC",
  "postal": "94043",
  "timezone": "America/Los_Angeles",
  "readme": "https://ipinfo.io/missingauth"
}

Will change it so hostname is optional.

UmanShahzad commented 3 years ago

https://crates.io/crates/ipinfo/0.2.0 contains this update.