'str' object has no attribute 'items'

yjay 256 Reputation points

I'm trying to consume a model that I deployed from Azure Machine Learning as a web service but I keep getting an error: 'str' object has no attribute 'items' Help: https://go.microsoft.com/fwlink/?linkid=2146748.

I am following the Consume an Azure Machine Learning model deployed as a web service tutorial for calling the service using python.

I followed the formatting as shown in the documentation but I still keep getting this error.

import requests  
import json  
# URL for the web service  
scoring_uri = ''  
# If the service is authenticated, set the key or token  
# Two sets of data to score, so we get two results back  
data = {"data":  
            {'volume': 0.23,   
             'temp': 0.66, }  
# Convert to JSON string  
input_data = json.dumps(data)  
# Set the content type  
headers = {'Content-Type': 'application/json'}  
# Make the request and display the response  
resp = requests.post(scoring_uri, input_data, headers=headers)  

Any ideas would be great, thanks!

Scoring script:

import os  
import json  
from azureml.studio.core.io.model_directory import ModelDirectory  
from pathlib import Path  
from azureml.studio.modules.ml.score.score_generic_module.score_generic_module import ScoreModelModule  
from azureml.designer.serving.dagengine.converter import create_dfd_from_dict  
from collections import defaultdict  
from azureml.designer.serving.dagengine.utils import decode_nan  
from azureml.studio.common.datatable.data_table import DataTable  
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'trained_model_outputs')  
schema_file_path = Path(model_path) / '_schema.json'  
with open(schema_file_path) as fp:  
    schema_data = json.load(fp)  
def init():  
    global model  
    model = ModelDirectory.load(model_path).model  
def run(data):  
    data = json.loads(data)  
    input_entry = defaultdict(list)  
    for row in data:  
        for key, val in row.items():  
    data_frame_directory = create_dfd_from_dict(input_entry, schema_data)  
    score_module = ScoreModelModule()  
    result, = score_module.run(  
    return json.dumps({"result": result.data_frame.values.tolist()})  
Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,242 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,072 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ramr-msft 16,216 Reputation points

    @yjay Thanks, Here is the example, for the Multiclass Classification - Letter Recognition sample, the inference results are as follows:


    0 comments No comments