Cannot pull a file from the workspace with 'get_relative_path'

Hello,

I have a .json file with my BigQuery credentials that I’m trying to get my app to pull using “get_relative_path”.

But when using that function I’m getting an error that the app cannot use the file.

Here is my file structure:
image

Here is the code I’m using in the app

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= dash.get_relative_path('/service_key.json')

And this is the error I’m getting:

/Workspaces/view/demand-forecast-stats-models/service_key.json
Traceback (most recent call last):
  File "/workspace/app.py", line 26, in <module>
    app = Dash(__name__, use_pages=True)
  File "/app/.heroku/python/lib/python3.7/site-packages/dash/dash.py", line 494, in __init__
    self.init_app()
  File "/app/.heroku/python/lib/python3.7/site-packages/dash/dash.py", line 578, in init_app
    self.enable_pages()
  File "/app/.heroku/python/lib/python3.7/site-packages/dash/dash.py", line 2044, in enable_pages
    self._import_layouts_from_pages()
  File "/app/.heroku/python/lib/python3.7/site-packages/dash/dash.py", line 2016, in _import_layouts_from_pages
    spec.loader.exec_module(page_module)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/workspace/pages/ind_item.py", line 37, in <module>
    client = bigquery.Client(project="gcp-sc-demand-plan-analytics")
  File "/app/.heroku/python/lib/python3.7/site-packages/google/cloud/bigquery/client.py", line 230, in __init__
    _http=_http,
  File "/app/.heroku/python/lib/python3.7/site-packages/google/cloud/client/__init__.py", line 322, in __init__
    self, credentials=credentials, client_options=client_options, _http=_http
  File "/app/.heroku/python/lib/python3.7/site-packages/google/cloud/client/__init__.py", line 178, in __init__
    credentials, _ = google.auth.default(scopes=scopes)
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/_default.py", line 620, in default
    credentials, project_id = checker()
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/_default.py", line 613, in <lambda>
    lambda: _get_explicit_environ_credentials(quota_project_id=quota_project_id),
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/_default.py", line 234, in _get_explicit_environ_credentials
    os.environ[environment_vars.CREDENTIALS], quota_project_id=quota_project_id
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/_default.py", line 122, in load_credentials_from_file
    "File {} was not found.".format(filename)
google.auth.exceptions.DefaultCredentialsError: File /Workspaces/view/demand-forecast-stats-models/service_key.json was not found.

I’m not sure how to “correctly” use the get_relative_path where the code will work not only locally but when I deploy this app?