@Oweys - Thanks for the question and uisng MS Q&A platform.
The issue you are facing seems to be related to the format of the SAS token that you are generating with Python. The SAS token format is crucial, and even a small difference in formatting can lead to authentication errors. Let's go through your code and identify the issue.
Here's the manually generated SAS token for reference:
sp=rl&st=2023-11-07T20:00:00Z&se=2023-11-08T03:00:00Z&spr=https&sv=2022-11-02&sr=c&sig=<sig...>
And here's the Python-generated SAS token:
se=2023-11-08T00%3A26%3A51Z&sp=rl&spr=https&sv=2023-08-03&sr=c&sig=<sig...>
The differences between the two tokens are the date/time format, the version (sv
), and possibly other factors. Let's address these issues one by one.
Date/Time Format: The date and time format in the manually generated token is in a specific ISO 8601 format. In the Python-generated token, you are encoding the time with URL encoding (e.g., %3A
for :
). You should format the datetime correctly in ISO 8601 format.
Version (sv
): The manually generated token specifies sv=2022-11-02
, which is the SAS token version. In your Python code, you're using sv=2023-08-03
. Make sure to use the correct SAS token version. You should use the same version as the one that works, which seems to be sv=2022-11-02
.
Check Other Parameters: Make sure that all other parameters, such as sp
(permissions), spr
(protocol), and sr
(resource type), are consistent with the manually generated token.
Here's how you can modify your _generate_sas_token
function to ensure the correct formatting:
from azure.storage.blob import generate_container_sas, ContainerSasPermissions
def _generate_sas_token(self, account_name, account_key, container_name, expiry_time, start_time):
permissions = ContainerSasPermissions(read=True, list=True)
sas_token = generate_container_sas(
account_name=account_name,
account_key=account_key,
container_name=container_name,
permission=permissions,
expiry=expiry_time,
start=start_time,
protocol='https',
version='2022-11-02' # Use the correct version
)
self.logger_inst.info("Created SAS Token.")
return sas_token
Ensure that you pass the correct version ('2022-11-02') as shown above and format the start_time
and expiry_time
as ISO 8601 datetime strings.
After making these changes, your Python-generated SAS token should match the manually generated one, and it should work correctly for accessing your Azure Data Lake container.
I hope this information helps. If you have any further questions or need more clarification, please let me know.