I'm trying to test an upload file with azurite with my code
from datetime import datetime, timedelta
import requests
from azure.storage.blob import BlobSasPermissions, BlobServiceClient, generate_blob_sas
connect_str = "DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
container_name = "files"
blob_name = "device.log"
account_key = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
blob_client = blob_service_client.get_blob_client(
container=container_name, blob=blob_name
)
sas_token = generate_blob_sas(
account_name="devstoreaccount1",
account_key="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
container_name=container_name,
blob_name="myblob",
permission=BlobSasPermissions(create=True),
expiry=datetime.utcnow() + timedelta(hours=1),
)
upload_url = blob_client.url + "?" + sas_token
print(upload_url)
local_path = "/home/nixos/nimbus/airfriskcomm/data/log/device.log"
with open(local_path, "rb") as file:
file_contents = file.read()
headers = {
"x-ms-blob-type": "BlockBlob",
"Content-Type": "application/octet-stream",
"Content-Length": str(len(file_contents)),
}
response = requests.put(upload_url, data=file_contents, headers=headers)
print(response.status_code)
but I keep on getting the response status code 403. I guess there is some problem in sas token I'm generating.