Closed munterfi closed 3 years ago
With the development version of the package, the rate limits of the APIs are now considered in the requests:
library(hereR)
set_verbose(TRUE)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
geocode <- geocode(address = poi$city)
#> Sending 8 request(s) with 5 RPS to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 8 response(s) with total size: 5.3 Kb
autosuggest <- autosuggest(address = poi$city, results = 3)
#> Sending 8 request(s) with 5 RPS to: 'https://revgeocode.search.hereapi.com/v1/autosuggest?...'
#> Received 8 response(s) with total size: 11.8 Kb
reverse_geocode <- reverse_geocode(poi = poi, results = 3)
#> Sending 8 request(s) with 5 RPS to: 'https://revgeocode.search.hereapi.com/v1/revgeocode?...'
#> Received 8 response(s) with total size: 16 Kb
route <- route(origin = poi[1:2, ], destination = poi[3:4, ])
#> Sending 2 request(s) with 10 RPS to: 'https://router.hereapi.com/v8/routes?...'
#> Received 2 response(s) with total size: 50 Kb
route_matrix <- route_matrix(origin = poi)
#> Sending 1 request(s) with 1 RPS to: 'https://matrix.router.hereapi.com/v8/matrix?...'
#> Received 1 response(s) with total size: 1.2 Kb
intermodal_route <- intermodal_route(
origin = poi[1:3, ], destination = poi[4:6, ]
)
#> Sending 3 request(s) with 5 RPS to: 'https://intermodal.router.hereapi.com/v8/routes?...'
#> Received 3 response(s) with total size: 105.1 Kb
isoline <- isoline(poi = poi)
#> Sending 8 request(s) with 1 RPS to: 'https://isoline.router.hereapi.com/v8/isolines?...'
#> Received 8 response(s) with total size: 92.9 Kb
weather_observation <- weather(poi = poi, product = "observation")
#> Sending 8 request(s) with unlimited RPS to: 'https://weather.ls.hereapi.com/weather/1.0/report.json?...'
#> Received 8 response(s) with total size: 59.7 Kb
weather_forecast_hourly <- weather(poi = poi, product = "forecast_hourly")
#> Sending 8 request(s) with unlimited RPS to: 'https://weather.ls.hereapi.com/weather/1.0/report.json?...'
#> Received 8 response(s) with total size: 897.6 Kb
weather_forecast_astronomy <- weather(
poi = poi, product = "forecast_astronomy"
)
#> Sending 8 request(s) with unlimited RPS to: 'https://weather.ls.hereapi.com/weather/1.0/report.json?...'
#> Received 8 response(s) with total size: 19.1 Kb
weather_alerts <- weather(poi = poi, product = "alerts")
#> Sending 8 request(s) with unlimited RPS to: 'https://weather.ls.hereapi.com/weather/1.0/report.json?...'
#> Received 8 response(s) with total size: 5.1 Kb
flow <- flow(aoi = aoi[aoi$code == "LI", ])
#> Sending 1 request(s) with unlimited RPS to: 'https://traffic.ls.hereapi.com/traffic/6.2/flow.json?...'
#> Received 1 response(s) with total size: 310.2 Kb
incident <- incident(aoi = aoi, from = Sys.time() - 60 * 60 * 0.5)
#> Sending 2 request(s) with unlimited RPS to: 'https://traffic.ls.hereapi.com/traffic/6.2/incidents.json?...'
#> Received 2 response(s) with total size: 160.9 Kb
connection_section <- connection(
origin = poi[3:4, ], destination = poi[5:6, ], results = 2, summary = FALSE
)
#> Sending 2 request(s) with 10 RPS to: 'https://transit.router.hereapi.com/v8/routes?...'
#> Received 2 response(s) with total size: 70.5 Kb
connection_summary <- connection(
origin = poi[3:4, ], destination = poi[5:6, ], results = 2, summary = TRUE
)
#> Sending 2 request(s) with 10 RPS to: 'https://transit.router.hereapi.com/v8/routes?...'
#> Received 2 response(s) with total size: 70.5 Kb
station <- station(poi)
#> Sending 8 request(s) with 10 RPS to: 'https://transit.hereapi.com/v8/stations?...'
#> Received 8 response(s) with total size: 43.3 Kb
Testing with some more requests:
geocode(rep(poi$city, 20))
#> Sending 160 request(s) with 5 RPS to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 160 response(s) with total size: 103 Kb
#> Simple feature collection with 160 features and 16 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 6.14275 ymin: 46.00297 xmax: 9.52164 ymax: 47.5488
#> Geodetic CRS: WGS 84
#> First 10 features:
#> id rank address type street house_number postal_code
#> 1 1 1 Luzern, Schweiz locality <NA> <NA> 6003
#> 2 2 1 Lugano, Ticino, Svizzera locality <NA> <NA> 6900
#> 3 3 1 Lausanne, Vaud, Suisse locality <NA> <NA> 1003
#> 4 4 1 Basel, Basel-Stadt, Schweiz locality <NA> <NA> 4051
#> 5 5 1 Bern, Schweiz locality <NA> <NA> 3011
#> 6 6 1 Zürich, Schweiz locality <NA> <NA> 8001
#> 7 7 1 Genève, Suisse locality <NA> <NA> 1201
#> 8 8 1 Vaduz, Liechtenstein locality <NA> <NA> 9490
#> 9 9 1 Luzern, Schweiz locality <NA> <NA> 6003
#> 10 10 1 Lugano, Ticino, Svizzera locality <NA> <NA> 6900
#> state_code country_code district city county state
#> 1 LU CHE <NA> Luzern Luzern-Stadt Luzern
#> 2 TI CHE <NA> Lugano Lugano Ticino
#> 3 VD CHE <NA> Lausanne Lausanne Vaud
#> 4 BS CHE <NA> Basel Basel-Stadt Basel-Stadt
#> 5 BE CHE <NA> Bern Bern-Mittelland Bern
#> 6 ZH CHE <NA> Zürich Zürich Zürich
#> 7 GE CHE <NA> Genève Genève Genève
#> 8 <NA> LIE <NA> Vaduz Oberland <NA>
#> 9 LU CHE <NA> Luzern Luzern-Stadt Luzern
#> 10 TI CHE <NA> Lugano Lugano Ticino
#> country score access geometry
#> 1 Schweiz 1 POINT EMPTY POINT (8.30437 47.04954)
#> 2 Svizzera 1 POINT EMPTY POINT (8.9512 46.00297)
#> 3 Suisse 1 POINT EMPTY POINT (6.63222 46.5196)
#> 4 Schweiz 1 POINT EMPTY POINT (7.58781 47.5488)
#> 5 Schweiz 1 POINT EMPTY POINT (7.44046 46.94843)
#> 6 Schweiz 1 POINT EMPTY POINT (8.53977 47.377)
#> 7 Suisse 1 POINT EMPTY POINT (6.14275 46.20833)
#> 8 Liechtenstein 1 POINT EMPTY POINT (9.52164 47.13879)
#> 9 Schweiz 1 POINT EMPTY POINT (8.30437 47.04954)
#> 10 Svizzera 1 POINT EMPTY POINT (8.9512 46.00297)
Turn off rate limits and check again:
set_rate_limit(FALSE)
geocode(rep(poi$city, 20))
#> Sending 160 request(s) with unlimited RPS to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 22' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 24' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 25' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 27' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 28' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 30' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 31' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 32' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 34' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 36' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 37' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 38' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 39' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 40' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 41' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 42' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 43' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 44' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 45' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 46' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 47' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 48' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 49' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 50' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 51' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 52' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 53' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 54' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 55' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 58' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 60' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 61' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 62' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 63' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 64' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 65' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 66' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 67' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 68' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 69' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 70' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 71' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 72' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 73' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 76' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 78' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 79' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 80' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 81' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 82' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 83' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 84' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 85' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 86' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 87' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 88' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 89' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 90' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 91' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 94' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 96' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 97' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 98' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 99' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 100' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 101' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 102' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 103' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 104' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 105' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 106' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 107' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 108' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 109' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 113' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 114' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 115' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 116' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 117' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 118' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 119' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 120' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 121' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 122' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 123' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 124' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 125' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 126' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 127' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 131' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 132' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 133' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 134' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 135' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 136' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 137' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 138' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 139' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 140' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 141' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 142' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 143' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 144' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 145' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 149' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 150' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 151' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 152' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 153' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 154' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 155' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 156' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 157' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 158' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 159' failed:
#> Status 429.
#> Warning in .parse_response(i, out$responses()[[i]]): Request 'id = 160' failed:
#> Status 429.
#> Received 160 response(s) with total size: 37.6 Kb
#> Simple feature collection with 44 features and 16 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 6.14275 ymin: 46.00297 xmax: 9.52164 ymax: 47.5488
#> Geodetic CRS: WGS 84
#> First 10 features:
#> id rank address type street house_number postal_code
#> 1 1 1 Luzern, Schweiz locality <NA> <NA> 6003
#> 2 2 1 Lugano, Ticino, Svizzera locality <NA> <NA> 6900
#> 3 3 1 Lausanne, Vaud, Suisse locality <NA> <NA> 1003
#> 4 4 1 Basel, Basel-Stadt, Schweiz locality <NA> <NA> 4051
#> 5 5 1 Bern, Schweiz locality <NA> <NA> 3011
#> 6 6 1 Zürich, Schweiz locality <NA> <NA> 8001
#> 7 7 1 Genève, Suisse locality <NA> <NA> 1201
#> 8 8 1 Vaduz, Liechtenstein locality <NA> <NA> 9490
#> 9 9 1 Luzern, Schweiz locality <NA> <NA> 6003
#> 10 10 1 Lugano, Ticino, Svizzera locality <NA> <NA> 6900
#> state_code country_code district city county state
#> 1 LU CHE <NA> Luzern Luzern-Stadt Luzern
#> 2 TI CHE <NA> Lugano Lugano Ticino
#> 3 VD CHE <NA> Lausanne Lausanne Vaud
#> 4 BS CHE <NA> Basel Basel-Stadt Basel-Stadt
#> 5 BE CHE <NA> Bern Bern-Mittelland Bern
#> 6 ZH CHE <NA> Zürich Zürich Zürich
#> 7 GE CHE <NA> Genève Genève Genève
#> 8 <NA> LIE <NA> Vaduz Oberland <NA>
#> 9 LU CHE <NA> Luzern Luzern-Stadt Luzern
#> 10 TI CHE <NA> Lugano Lugano Ticino
#> country score access geometry
#> 1 Schweiz 1 POINT EMPTY POINT (8.30437 47.04954)
#> 2 Svizzera 1 POINT EMPTY POINT (8.9512 46.00297)
#> 3 Suisse 1 POINT EMPTY POINT (6.63222 46.5196)
#> 4 Schweiz 1 POINT EMPTY POINT (7.58781 47.5488)
#> 5 Schweiz 1 POINT EMPTY POINT (7.44046 46.94843)
#> 6 Schweiz 1 POINT EMPTY POINT (8.53977 47.377)
#> 7 Suisse 1 POINT EMPTY POINT (6.14275 46.20833)
#> 8 Liechtenstein 1 POINT EMPTY POINT (9.52164 47.13879)
#> 9 Schweiz 1 POINT EMPTY POINT (8.30437 47.04954)
#> 10 Svizzera 1 POINT EMPTY POINT (8.9512 46.00297)
Note: Paid plans should use set_rate_limit(FALSE)
to avoid the limits.
This is a great solution, thank you! Very annoying change from HERE, figured it out when I started getting all sorts of 429 errors, ugh.
Describe the bug Unfortunately HERE introduced rate limits on freemium licenses:
For freemium licenses requests fail randomly with status code
429
on all API endpoints if they exceed the rate limit.Reproducible example
Expected behavior Add sleep time if request code
429
is encountered and retry. Not sure if async requests are still the way to go... ?