-1

I am using python 3.7.8 and trying to access azure data lake account files getting this error.

dependencies version details:

azure-core                  1.13.0
azure-storage-blob          12.8.1
azure-storage-file-datalake 12.2.0
Flask                       1.1.2
Flask-Cors                  3.0.10
waitress                    2.0.0

apptest.py

import json
from flask_cors import CORS
import base64
import sys

from flask import Flask, request, jsonify
from azure.storage.filedatalake import DataLakeServiceClient

from azure.storage.blob import BlobServiceClient,generate_blob_sas, generate_account_sas, ResourceTypes, AccountSasPermissions,BlobSasPermissions

app = Flask(__name__)
app.config["DEBUG"] = True
CORS(app)
from waitress import serve


def get_service_client(requestPayLoad):
    try:  
        credentials=get_Credentials(requestPayLoad)
        service_client= DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format(
        "https", credentials['storage_account_name']), credential=credentials['storage_account_key'])
        return service_client
    except Exception as e:
     print(e)
def get_Credentials(requestPayLoad):
    storage_account_name= config['accountName'] if requestPayLoad["TypeOfData"]=='Private'else config['publicAccountName']
    storage_account_key= config['accountKey'] if requestPayLoad["TypeOfData"]=='Private'else config['publicAccountKey']
    return json.loads(json.dumps({"storage_account_name": storage_account_name, "storage_account_key": storage_account_key}))

server error:

[2021-08-13 09:35:56,632] ERROR in server: 'dict' object has no attribute 'iter'
ERROR:server:'dict' object has no attribute 'iter'
ERROR:waitress:Exception while serving /api/
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/waitress/channel.py", line 397, in service
    task.service()

could you please help me to solve the error?

Thanks.

cj devin
  • 1,045
  • 3
  • 13
  • 48

1 Answers1

1

Looks like the issue is because of passing credentials as two parameters and formatting account_url.

Instead try to pass the parameters as below:

from azure.storage.filedatalake import DataLakeServiceClient

service = DataLakeServiceClient(account_url="https://<my-storage-account-name>.dfs.core.windows.net/", credential=credential)

For more information about DataLakeServiceClient go through Azure Python SDK Docs

Also we can remove try except block to find the error trace or we can handle it in below way:

additional_data = {}
try:
    error_body = ContentDecodePolicy.deserialize_from_http_generics(storage_error.response)
    if error_body and hasattr(error_body, "iter"):
        for info in error_body:
            if info.tag.lower() == 'code':
                error_code = info.text

Please refer to the fixed issues in GIT for Dict Json errors

SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8