Hello,
When I Run and Debug this simple HTTP Trigger function which includes the library Requests, I obtain the errors "ERROR: Error: No module named 'requests', Cannot find module." "ModuleNotFoundError: No module named 'requests", knowing the requests package is installed in my local environment. Azure Function Core Tools is also installed.
Do you have any thoughts where this error could be coming from?
Thanks in advance for your help with this!
Versions:
- Python 3.11.9
- Azure Function Core Tools 4.0.5801
Package Version
---------------------- --------
azure-core 1.30.1
azure-functions 1.19.0
azure-identity 1.16.0
azure-keyvault-secrets 4.8.0
certifi 2024.2.2
cffi 1.16.0
charset-normalizer 3.3.2
cryptography 42.0.7
idna 3.7
isodate 0.6.1
msal 1.28.0
msal-extensions 1.1.0
packaging 24.0
pip 24.0
portalocker 2.8.2
pycparser 2.22
PyJWT 2.8.0
pywin32 306
requests 2.32.2
setuptools 65.5.0
six 1.16.0
typing_extensions 4.12.0
urllib3 2.2.1
requirements.txt
# DO NOT include azure-functions-worker in this file
# The Python Worker is managed by Azure Functions platform
# Manually managing azure-functions-worker may cause unexpected issues
azure-functions
requests
azure-identity
azure-keyvault-secrets
msal
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python",
"PYTHON_PATH": ".venv\\Scripts\\python.exe",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
function_app.py
import logging
import requests
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
response = requests.get("https://httpbin.org/get")
return func.HttpResponse(f"Response: {response.status_code}")
.vscode - extensions.json
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-python.python"
]
}
.vscode - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 9091
},
"preLaunchTask": "func: host start"
}
]
}
.vscode - settings.json
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2,
"python.defaultInterpreterPath": "C:\\<path>\\.venv\\Scripts\\python.exe" #Real path here
}
.vscode - tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"label": "func: host start",
"command": "host start",
"options": {
"env": {
"PYDEVD_DISABLE_FILE_VALIDATION": "1"
}
},
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pip install (functions)"
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": []
}
]
}