简体   繁体   中英

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?

You are referencing an old version of azure.storage.version v1.5.0, in the latest version, v12.xx, 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM