yjay-4307 avatar image
0 Votes"
yjay-4307 asked ramr-msft answered

'str' object has no attribute 'items'

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:

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 =, input_data, headers=headers)

Any ideas would be great, thanks!

Scoring script:

 import os
 import json
 from import ModelDirectory
 from pathlib import Path
 from 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 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, =
     return json.dumps({"result": result.data_frame.values.tolist()})

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@yjay-4307 Thanks for the question. The data str object expecting list of items. The structure of the data needs to match what the scoring script and model in the service expect. The scoring script might modify the data before passing it to the model.

0 Votes 0 ·

@ramr-msft thanks so much for your answer, I have tried modifying my code to contain a list of items but am still getting the error. I also tried following sample.json that I found for the trained model but that didn't either work. I have added the scoring script for further reference. Thanks again.

0 Votes 0 ·

@yjay-4307 Thanks for the details. You can diagnose the web service using get_logs method.


Please follow the samples for deployment and consume the deployed webservice.



0 Votes 0 ·
screenshot-210.png (20.5 KiB)
screenshot-209.png (17.7 KiB)

1 Answer

ramr-msft avatar image
0 Votes"
ramr-msft answered

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


screenshot-211.png (107.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.