onnela-lab / forest

Forest is a library for analyzing smartphone-based high-throughput digital phenotyping data
https://forest.beiwe.org
BSD 3-Clause "New" or "Revised" License
28 stars 16 forks source link

Access to this API has been disallowed #167

Closed jflournoy closed 1 year ago

jflournoy commented 1 year ago

I'm trying to implement the example in the README and get the following error: ApiError: 403 ({'error': 'Access to this API has been disallowed'}). Full error log below, and session information.

---------------------------------------------------------------------------
ApiError                                  Traceback (most recent call last)
File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/bonsai/simulate_gps_data.py:109, in get_path(start, end, transport, api_key)
    108 try:
--> 109     routes = client.directions(
    110         coords, profile=transport2, format="geojson"
    111         )
    112 except (openrouteservice.exceptions.ApiError,
    113         openrouteservice.exceptions.ValidationError,
    114         openrouteservice.exceptions.HTTPError,
    115         openrouteservice.exceptions.Timeout) as e:

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/openrouteservice/client.py:299, in _make_api_method.<locals>.wrapper(*args, **kwargs)
    298 args[0]._extra_params = kwargs.pop("extra_params", None)
--> 299 result = func(*args, **kwargs)
    300 try:

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/openrouteservice/directions.py:281, in directions(client, coordinates, profile, format_out, format, preference, units, language, geometry, geometry_simplify, instructions, instructions_format, alternative_routes, roundabout_exits, attributes, maneuvers, radiuses, bearings, skip_segments, continue_straight, elevation, extra_info, suppress_warnings, optimized, optimize_waypoints, options, validate, dry_run)
    279     params['options'] = options
--> 281 return client.request("/v2/directions/" + profile + '/' + format, {}, post_json=params, dry_run=dry_run)

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/openrouteservice/client.py:204, in Client.request(self, url, get_params, first_request_time, retry_counter, requests_kwargs, post_json, dry_run)
    203 try:
--> 204     result = self._get_body(response)
    206     return result

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/openrouteservice/client.py:242, in Client._get_body(response)
    241 if status_code != 200:
--> 242     raise exceptions.ApiError(
    243         status_code,
    244         body
    245     )
    247 return body

ApiError: 403 ({'error': 'Access to this API has been disallowed'})

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
Cell In[3], line 50
     22 # dictionary of personal attributes for each user, set to None if random, check Attributes class for usage in simulate_gps_data module.
     23 personal_attributes = {
     24     "User 1":
     25     {
   (...)
     48     }
     49 }
---> 50 sample_gps_data = sim_gps_data(n_persons, location, start_date, end_date, cycle, percentage, api_key, personal_attributes)
     51 # save data in format of csv files
     52 gps_to_csv(sample_gps_data, path_to_synthetic_gps_data, start_date, end_date)

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/bonsai/simulate_gps_data.py:1375, in sim_gps_data(n_persons, location, start_date, end_date, cycle, percentage, api_key, attributes_dict)
   1372 all_nodes = generate_nodes(house_address, attrs.main_occupation)
   1374 person = Person(house_address, attrs, all_nodes)
-> 1375 all_traj, all_times, all_distances = gen_all_traj(
   1376     person,
   1377     switches_dictionary[user + 1],
   1378     start_date,
   1379     end_date,
   1380     api_key,
   1381 )
   1382 if len(all_traj) == 0:
   1383     ind += 1

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/bonsai/simulate_gps_data.py:951, in gen_all_traj(person, switches, start_date, end_date, api_key)
    948 elif action.action == ActionType.FLIGHT_PAUSE_FLIGHT:
    949     d_temp = 0.
--> 951     go_path, transport = person.calculate_trip(
    952         person.home_coordinates, action.destination_coordinates,
    953         api_key
    954     )
    955     return_path, _ = person.calculate_trip(
    956         action.destination_coordinates, person.home_coordinates,
    957         api_key
    958     )
    959     # Flight 1

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/bonsai/simulate_gps_data.py:611, in Person.calculate_trip(self, origin, destination, api_key)
    609     path = self.trips[coords_str]
    610 else:
--> 611     path, _ = get_path(origin, destination, transport, api_key)
    612     path = get_basic_path(path, transport)
    613     self.trips[coords_str] = path

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/ratelimit/decorators.py:113, in sleep_and_retry.<locals>.wrapper(*args, **kargs)
    111 while True:
    112     try:
--> 113         return func(*args, **kargs)
    114     except RateLimitException as exception:
    115         time.sleep(exception.period_remaining)

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/ratelimit/decorators.py:80, in RateLimitDecorator.__call__.<locals>.wrapper(*args, **kargs)
     77             raise RateLimitException('too many calls', period_remaining)
     78         return
---> 80 return func(*args, **kargs)

File ~/.conda/envs/star_diph/lib/python3.8/site-packages/forest/bonsai/simulate_gps_data.py:116, in get_path(start, end, transport, api_key)
    109     routes = client.directions(
    110         coords, profile=transport2, format="geojson"
    111         )
    112 except (openrouteservice.exceptions.ApiError,
    113         openrouteservice.exceptions.ValidationError,
    114         openrouteservice.exceptions.HTTPError,
    115         openrouteservice.exceptions.Timeout) as e:
--> 116     raise RuntimeError(e.message)
    117 coordinates = routes["features"][0]["geometry"]["coordinates"]
    118 distance = routes["features"][0]["properties"]["summary"]["distance"]

RuntimeError: {'error': 'Access to this API has been disallowed'}

Click to view session information

-----
forest              NA
session_info        1.0.0
-----

Click to view modules imported as dependencies

asttokens                   NA
backcall                    0.2.0
certifi                     2022.12.07
cffi                        1.15.1
charset_normalizer          3.1.0
comm                        0.1.2
cython_runtime              NA
dateutil                    2.8.2
debugpy                     1.5.1
decorator                   5.1.1
executing                   0.8.3
h3                          3.7.6
idna                        3.4
importlib_metadata          NA
inside_polygon_ext          NA
ipykernel                   6.19.2
jedi                        0.18.1
llvmlite                    0.40.0
numba                       0.57.0
numpy                       1.24.3
openrouteservice            2.2.2
packaging                   23.0
pandas                      2.0.1
parso                       0.8.3
pexpect                     4.8.0
pickleshare                 0.7.5
pkg_resources               NA
platformdirs                2.5.2
prompt_toolkit              3.0.36
psutil                      5.9.0
ptyprocess                  0.7.0
pure_eval                   0.2.2
pycparser                   2.21
pydev_ipython               NA
pydevconsole                NA
pydevd                      2.6.0
pydevd_concurrency_analyser NA
pydevd_file_utils           NA
pydevd_plugins              NA
pydevd_tracing              NA
pygments                    2.11.2
pyproj                      3.5.0
pytz                        2023.3
ratelimit                   2.2.1
requests                    2.30.0
scipy                       1.10.1
shapely                     2.0.1
six                         1.16.0
stack_data                  0.2.0
timezonefinder              NA
tornado                     6.2
traitlets                   5.7.1
typing_extensions           NA
urllib3                     2.0.2
wcwidth                     0.2.5
zipp                        NA
zmq                         25.0.2

-----
IPython             8.12.0
jupyter_client      8.1.0
jupyter_core        5.3.0
-----
Python 3.8.16 (default, Mar  2 2023, 03:21:46) [GCC 11.2.0]
Linux-3.10.0-1160.36.2.el7.x86_64-x86_64-with-glibc2.17
-----
Session information updated at 2023-05-05 13:55
GeorgeEfstathiadis commented 1 year ago

This seems to be an error with your OpenRouteService API key. The 403 is issued if you go over your total daily quota or the API key you pass is not authorized.

You can check your quota at openrouteservice dashboard Check this post for more information

jflournoy commented 1 year ago

Thanks. This is why one should read the comments. Take note, kids.

# api key for openroute service, generated from https://openrouteservice.org/
api_key = "mock_api_key"