Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python import error when using auth_type="oauth-m2m" #162

Closed
dmoore247 opened this issue Jun 10, 2023 · 2 comments · Fixed by #186
Closed

Python import error when using auth_type="oauth-m2m" #162

dmoore247 opened this issue Jun 10, 2023 · 2 comments · Fixed by #186

Comments

@dmoore247
Copy link

Import error when using auth_type="oauth-m2m"
When running this python statement:

a = AccountClient(auth_type="oauth-m2m", profile="E2CERTACCT")

I found the error below while running in the python debugger.

 File "/Users/xxxxxx.xxxxxxxx/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 23, in <module>
    from .azure import ARM_DATABRICKS_RESOURCE_ID, ENVIRONMENTS, AzureEnvironment
ImportError: attempted relative import with no known parent package

log:

2023-06-09 22:53:01,090 [databricks.sdk][INFO] loading E2CERTACCT profile from ~/.databrickscfg: host, account_id, client_id, client_secret
2023-06-09 22:53:01,090 [databricks.sdk][DEBUG] Ignoring pat auth, because oauth-m2m is preferred
2023-06-09 22:53:01,090 [databricks.sdk][DEBUG] Ignoring basic auth, because oauth-m2m is preferred
2023-06-09 22:53:01,090 [databricks.sdk][DEBUG] Ignoring metadata-service auth, because oauth-m2m is preferred
2023-06-09 22:53:01,090 [databricks.sdk][DEBUG] Attempting to configure auth: oauth-m2m
Traceback (most recent call last):
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 415, in __call__
    header_factory = provider(cfg)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 60, in wrapper
    return func(cfg)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 114, in oauth_service_principal
    token_url=resp.json()["token_endpoint"],
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 775, in _init_auth
    self._header_factory = self._credentials_provider(self)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 421, in __call__
    raise ValueError(f'{auth_type}: {e}') from e
ValueError: oauth-m2m: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 496, in __init__
    self._init_auth()
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 780, in _init_auth
    raise ValueError(f'{self._credentials_provider.auth_type()} auth: {e}') from e
ValueError: default auth: oauth-m2m: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/douglas.moore/development/dba-helper/permissions-graph/extract_account_principals.py", line 44, in <module>
    a = AccountClient(auth_type="oauth-m2m", profile="E2CERTACCT", debug_headers=True, debug_truncate_bytes=300)
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/__init__.py", line 192, in __init__
    config = client.Config(host=host,
  File "/Users/douglas.moore/.pyenv/versions/3.8.12/lib/python3.8/site-packages/databricks/sdk/core.py", line 501, in __init__
    raise ValueError(message) from e
ValueError: default auth: oauth-m2m: Expecting value: line 1 column 1 (char 0). Config: host=https://accounts.cloud.databricks.com, account_id=deadbeef-deadbeef-deadbeef, client_id=dead999-1234-4321-9999-deadbeef, client_secret=***, profile=E2CERTACCT, auth_type=oauth-m2m, debug_truncate_bytes=300, debug_headers=True
@dmoore247
Copy link
Author

dmoore247 commented Jun 10, 2023

.databrickscfg:

[E2CERTACCT]
host = https://accounts.cloud.databricks.com
account_id    = <account id>
client_id     = <client id>
client_secret = <secret>

package version:
databricks-sdk==0.1.9

@nfx
Copy link
Contributor

nfx commented Jun 10, 2023

you don't need auth_type if you already have profile. need to add some runtime checks. Most likely that account does not support M2M yet.

nfx added a commit that referenced this issue Jun 19, 2023
@nfx nfx closed this as completed in #186 Jun 19, 2023
nfx added a commit that referenced this issue Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants