0

I am trying to publish a machine learning model on Azure webservice using python. I am able to deploy the code successfully but when i try to call it through the URL, it's throwing me 'Azure' module doesn't exist. The code basically retrieves a TFIDF model from the container (blob) and use it to predict the new value. The error clearly says, Azure package is missing while trying to run on the webservice and I am not sure how to fix it. Here goes the code:

For deployment:

from azureml import services
from azure.storage.blob import BlobService
@services.publish('7c94eb2d9e4c01cbe7ce1063','f78QWNcOXHt9J+Qt1GMzgdEt+m3NXby9JL`npT7XX8ZAGdRZIX/NZ4lL2CkRkGQ==')
@services.types(res=unicode)
@services.returns(str)
def TechBot(res):
    from azure.storage.blob import BlobService
    from gensim.similarities import SparseMatrixSimilarity, MatrixSimilarity, Similarity
    blob_service = BlobService(account_name='tfidf', account_key='RU4R/NIVPsPOoR0bgiJMtosHJMbK1+AVHG0sJCHT6jIdKPRz3cIMYTsrQ5BBD5SELKHUXgBHNmvsIlhEdqUCzw==')
    blob_service.get_blob_to_path('techbot',"2014.csv","df")
    df=pd.read_csv("df")
    doct = res

To access the url I used the python code from

service.azureml.net

import urllib2
import json
import requests
data = {
        "Inputs": {
                "input1":
                [
                    {
                            'res': "wifi wnable",   
                    }
                ],
        },
    "GlobalParameters":  {
    }
}

body = str.encode(json.dumps(data))

#proxies = {"http":"http://%s" % proxy}
url = 'http://ussouthcentral.services.azureml.net/workspaces/7c94eb2de26a45399e4c01cbe7ce1063/services/11943e537e0741beb466cd91f738d073/execute?api-version=2.0&format=swagger'
api_key = '8fH9kp67pEt3C6XK9sXDLbyYl5cBNEwYg9VY92xvkxNd+cd2w46sF1ckC3jqrL/m8joV7o3rsTRUydkzRGDYig==' # Replace this with the API key for the web service
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}

#proxy_support = urllib2.ProxyHandler(proxies)
#opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler(debuglevel=1))
#urllib2.install_opener(opener)

req = urllib2.Request(url, body, headers)

try:
    response = urllib2.urlopen(req, timeout=60)

    result = response.read()
    print(result)
except urllib2.HTTPError, error:
    print("The request failed with status code: " + str(error.code))

    # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
    print(error.info())
    print(json.loads(error.read())) 

The string 'res' will be predicted at the end. As I said it runs perfectly fine if I run as it is in python by calling azure module, problem happens when I access the url. Any help is appreciated, please let me know if you need more information (I only sohwcased half of my code)

Sincole Brans
  • 186
  • 12

1 Answers1

1

I tried to reproduce the issue via POSTMAN, then I got the error information below as you said.

{
  "error": {
    "code": "ModuleExecutionError",
    "message": "Module execution encountered an error.",
    "details": [
      {
        "code": "85",
        "target": "Execute Python Script RRS",
        "message": "Error 0085: The following error occurred during script evaluation, please view the output log for more information:\r\n---------- Start of error message from Python interpreter ----------\r\nCaught exception while executing function: Traceback (most recent call last):\n  File \"\\server\\InvokePy.py\", line 120, in executeScript\n    outframe = mod.azureml_main(*inframes)\n  File \"\\temp\\1280677032.py\", line 1094, in azureml_main\n  File \"<ipython-input-15-bd03d199b8d9>\", line 6, in TechBot_2\nImportError: No module named azure\n\r\n\r\n---------- End of error message from Python  interpreter  ----------"
      }
    ]
  }
}

According to the error code 00085 & the information ImportError: No module named azure, I think the issue was caused by importing python moduleazure-storage. There was a similar SO thread Access Azure blog storage from within an Azure ML experiment which got the same issue, I think you can refer to its answer try to use HTTP protocol instead HTTPS in your code to resolve the issue as the code client = BlobService(STORAGE_ACCOUNT, STORAGE_KEY, protocol="http").

Hope it helps. Any concern & update, please feel free to let me know.


Update: Using HTTP protocol for BlobService

from azureml import services
from azure.storage.blob import BlobService
@services.publish('7c94eb2d9e4c01cbe7ce1063','f78QWNcOXHt9J+Qt1GMzgdEt+m3NXby9JL`npT7XX8ZAGdRZIX/NZ4lL2CkRkGQ==')
@services.types(res=unicode)
@services.returns(str)
def TechBot(res):
    from azure.storage.blob import BlobService
    from gensim.similarities import SparseMatrixSimilarity, MatrixSimilarity, Similarity
# Begin: Update code
# Using `HTTP` protocol for BlobService 
    blob_service = BlobService(account_name='tfidf', 
              account_key='RU4R/NIVPsPOoR0bgiJMtosHJMbK1+AVHG0sJCHT6jIdKPRz3cIMYTsrQ5BBD5SELKHUXgBHNmvsIlhEdqUCzw==', 
              protocol='http')
# End
    blob_service.get_blob_to_path('techbot',"2014.csv","df")
    df=pd.read_csv("df")
    doct = res
Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • I updated the protocol for blobservice and used http in the url, now Iam getting "URLError: – Sincole Brans Feb 20 '17 at 20:47
  • Updated the script to reflect 'Http' and timeout variable – Sincole Brans Feb 20 '17 at 21:22
  • @SincoleBrans You misunderstood my mean. I suggested you try to access Azure Blob Storage within SDK using `HTTP` protocol, not use `http://` instead of `https://` in azureml web service url. Please see my update code for your azureml deployment . – Peter Pan Feb 21 '17 at 08:17
  • I did change the protocol in blob servie and still getting the following error: 'The operation could not be completed within the permitted time.', u'code': u'RequestTimeout', u'details': [{u'message': u'Execution request timed out.', u'code': u'ScoreRequestTimeout'}] I tried changing timeout param in request to like 1000, still same error – Sincole Brans Feb 22 '17 at 05:51