2

I am trying to put together an Azure function to run on an HTTP trigger. My problem is whenever I run the function I get a key error exception from the six module. It seems to be called when importing pandas and I cannot figure out why. Here is the traceback:

Exception has occurred: KeyError
'six.moves'
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/six.py", line 198, in load_module
    return sys.modules[fullname]
  File "/Users/benjaminhack/Desktop/GenesisAnalytics/Sentiment Analysis/Pipleines/functions/HttpTrigger1/__init__.py", line 2, in <module>
    import pandas as pd
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/loader.py", line 76, in load_function
    mod = importlib.import_module(fullmodname)
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call
    return func(*args, **kwargs)
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 275, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 242, in _dispatch_grpc_request
    resp = await request_handler(request)
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/main.py", line 48, in main
    args.host, args.port, args.worker_id, args.request_id))
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/worker.py", line 86, in <module>
    main.main()

The code is supposed to run a function on an HTTP trigger where the function uses pandas.The following code snippet from the function's __init__.py has the import statement where the error occurs:

import logging
import pandas as pd
import azure.functions as func

from .scraper import total_scrape
from .cleaning_analysis import clean_tweets, run_sentiment_analysis

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    ### SCRAPE ###
    logging.info("Initiating scrape")
    df = total_scrape()
    logging.info("Scraping complete")
    logging.info("Shape: {}".format(df.shape))

    ### CLEAN ###
    
    df = clean_tweets(df)

    logging.info("Cleaning complete")

    ### ANALYSIS ###
    df = run_sentiment_analysis(df)
    logging.info("Sentiment Analysis completed")
    
    return func.HttpResponse(f"{df.info}")

Any help would be greatly appreciated. Thank you!

Ben
  • 41
  • 5

1 Answers1

1

It turns out my problems arose from a badly configured local environment. After redoing the virtual environment it sorted itself out quite well.

Ben
  • 41
  • 5
  • Could you give some more information on what you mean by a 'badly configured' local environment. I just deleted my local environment and recreated and still get the a KeyError for six.moves. I don't reference six in my requirements.txt either. – Dirk R Feb 01 '22 at 17:13