pythonazuresql-agent-job

Issue when running code from SQL server agent - azure.storage.blob - module azure not found


I'm having a problem with some python code that connects to an azure storage container.

Code:

from azure.storage.blob import BlockBlobService
import logging
import os, sys

block_blob_service = BlockBlobService(account_name = accountName, account_key = accountKey, connection_string=connectionString)

block_blob_service.create_blob_from_path(containerName,blob_name=blobName,file_path=fileNameToUpload)

Ok, so this code works when executed using a command prompt.

When its executed using a SQL agent job:

line 1, in from azure.storage.blob import BlockBlobService ModuleNotFoundError: No module named 'azure'. Process Exit Code 1. The step failed.

pip list:

azure-common         1.1.27
azure-core           1.19.0
azure-storage-blob   1.5.0
azure-storage-common 1.4.2

Using python 3.7.4

The credential that I use to run the SQL agent job is mapped to my userid which has admin privileges on the server.

I used the quickstart to get me started.

Can anyone help please?


Solution

  • You are referencing an old version of azure.storage.version v1.5.0, in the latest version, v12.x.x, you need to use BlobServiceClient instead.

    ######################################
    pip install azure-storage-blob==12.9.0
    ######################################
    
    blob_service_client = BlobServiceClient(account_url=url, credential=self._account_key)
    

    The link you mentioned it's already pointing to the latest version