Repository navigation
Closed
Labels
Description
- What versions are you using?
3.4.0
- Is it an error or a hang or a crash?
Error.
- What error(s) or behavior you are seeing?
Traceback (most recent call last):
File "src/oracledb/impl/base/connect_params.pyx", line 367, in oracledb.base_impl.ConnectParamsImpl._set_access_token
File "src/oracledb/impl/base/connect_params.pyx", line 294, in oracledb.base_impl.ConnectParamsImpl._get_token_expires
File "/Users/maros/.pyenv/versions/3.10.13/lib/python3.10/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/maros/Gitlab/dagster/data-ops/test.py", line 12, in <module>
conn = oracledb.connect(
File "/Users/maros/Library/Caches/pypoetry/virtualenvs/data-ops-pkPRkd2D-py3.10/lib/python3.10/site-packages/oracledb/connection.py", line 1698, in connect
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
File "/Users/maros/Library/Caches/pypoetry/virtualenvs/data-ops-pkPRkd2D-py3.10/lib/python3.10/site-packages/oracledb/connection.py", line 868, in __init__
dsn = params_impl.process_args(dsn, kwargs, thin)
File "src/oracledb/impl/base/connect_params.pyx", line 567, in oracledb.base_impl.ConnectParamsImpl.process_args
File "src/oracledb/impl/base/connect_params.pyx", line 109, in oracledb.base_impl.ConnectParamsImpl.set
File "src/oracledb/impl/base/connect_params.pyx", line 387, in oracledb.base_impl.ConnectParamsImpl._set_access_token_param
File "src/oracledb/impl/base/connect_params.pyx", line 369, in oracledb.base_impl.ConnectParamsImpl._set_access_token
File "/Users/maros/Library/Caches/pypoetry/virtualenvs/data-ops-pkPRkd2D-py3.10/lib/python3.10/site-packages/oracledb/errors.py", line 199, in _raise_err
raise error.exc_type(error) from cause
oracledb.exceptions.ProgrammingError: DPY-2031: invalid access token: value must be a string (for OAuth), a 2-tuple containing the token and private key strings (for IAM), or a callable that returns a string or 2-tuple
Incorrect padding
- Does your application call init_oracle_client()?
No.
- Include a runnable Python script that shows the problem.
import oracledb
import azure.identity
access_token = azure.identity.DefaultAzureCredential().get_token("https://<hostname>/<db_name>/.default").token
conn = oracledb.connect(
host="<db_host>",
service_name="<db_service_name>",
access_token=access_token,
)
with conn.cursor() as cursor:
r = cursor.execute("SELECt 1 from dual").fetchall()
print(r)
Reacted by Yi-Fan Wang, Savan Soni and Vladislav Wohlrath
Activity
savansonii commentedon Nov 13, 2025
It seems the string you’re decoding with binascii.a2b_base64() isn’t correctly padded or formatted as valid Base64, which is causing this issue.
Maros112358 commentedon Nov 14, 2025
Hello @savansonii, I contacted Azure Support about this matter and according to them, the Entra ID tokens are correct. I can also confirm that the newest Oracle JDBC Driver 23.26.0.0 parses them correctly. Here's the response from Azure Support:
Based on this I assume
python-oracledbdoes not parse the Azure Entra ID tokens correctly and assumes they are padded, while Azure Support confirmed they are not padded according to industry standard Base64URL encoding without padding. I assume that this can be fixed by using a Base64URL decoding method inpython-oracledb.Maros112358 commentedon Nov 14, 2025
I created a PR with the fix. To avoid the complicated approval process, please create your own PR with the fix. I tested it locally with tokens from Azure EntraID (which triggered the reported error), and the fix resolved the issue successfully.
vladidobro commentedon Nov 19, 2025
Hello,
I too have looked into this, and I am a little bit confused by the code the code that @Maros112358 fixes in his PR, namely the function
The part
seems to try to compute and add the needed padding, but I think that the padding is wrong, the last line should instead read
I don't know how this line could have worked before, so maybe I am in the wrong here.
Also, the token that comes from
azure.DefaultAzureCredential.get_tokenis not standard base64, but instead base64url.I don't know about other OAuth providers, but at least my tokens (which correctly authenticate me in the database) contain the characters '-' and '_'.
So the use of
base64.b64decodeis wrong, because it simply ignores these charactersOn the other hand, using urlsafe_b64decode as @Maros112358 suggests, interprets correctly the '_', '-' characters, but is also compatible with the standard b64decode and so interprets the '/' and '+' characters correctly as well.
Even though the base64url standard states that padding is unnecessary and should be filled automatically, the python implementation of urlsafe_b64decode does raise error on incorrect padding, but what's weird is that it requires at least the correct padding, but strips all unnecessary padding
so I think that this peculiar implementation detail partially hides the bug with incorrect padding in oracledb-python.
I suggest the fixed function looks like this
(I have not tested it)
anthony-tuininga commentedon Nov 21, 2025
@Maros112358, does this comment suggest your PR should be adjusted? Did you test it yourself? I have asked for this to be tested internally. Apologies for the delay!
Maros112358 commentedon Nov 26, 2025
Hello @anthony-tuininga, yes, please. I tested it with the same token both in
python-oracledb=3.4.0and with the_get_token_expiresthat @vladidobro described. Inpython-oracledb=3.4.0the access_token threw the error I mentioned in the first post, and worked correctly with the_get_token_expiresfunction from @vladidobro:Addressed issues reported in #548.
anthony-tuininga commentedon Nov 28, 2025
I have pushed a patch that should correct this issue and have initated a build from which you can download pre-built development wheels once it completes. You can also build from source if you prefer. If you can test your scenario and confirm the patch works as expected, that would be appreciated!
Maros112358 commentedon Dec 1, 2025
Hello @anthony-tuininga , I have just tested the wheel
oracledb-3.5.0b1-cp311-cp311-macosx_10_9_universal2.whland it works as expected. Thank you.Maros112358 commentedon Dec 9, 2025
Hello @anthony-tuininga, when can we expect the full release with the fix?
anthony-tuininga commentedon Dec 9, 2025
There are no definite plans at this point but likely sometime in January.
Maros112358 commentedon Jan 14, 2026
Hello @anthony-tuininga, any updates?
anthony-tuininga commentedon Jan 21, 2026
@Maros112358, I will be creating a new patch release in the next week or so.
Fixed bug when getting the expiry time of authentication tokens (#548).
anthony-tuininga commentedon Jan 23, 2026
I have initiated a new build on the
v3.4.xbranch in preparation for the release of python-oracledb 3.4.2.anthony-tuininga commentedon Jan 28, 2026
This was included in python-oracledb 3.4.2 which was just released.
Maros112358 commentedon Jan 29, 2026
Thank you very much.