Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何部署Azure功能,并确保更新包_Python_Azure_Azure Functions_Azure Cosmosdb - Fatal编程技术网

Python 如何部署Azure功能,并确保更新包

Python 如何部署Azure功能,并确保更新包,python,azure,azure-functions,azure-cosmosdb,Python,Azure,Azure Functions,Azure Cosmosdb,我让我的函数在本地工作,然后当我部署它们时,会出现如下错误: 结果:失败异常:ModuleNotFoundError:没有名为“azure.cosmosdb”的模块。疑难解答指南:Stack:File“/azure functions host/workers/python/3.8/LINUX/X64/azure\u functions\u worker/dispatcher.py”,第284行,在调用提升扩展异常消息中的第42行(e,message)文件“/azure functions ho

我让我的函数在本地工作,然后当我部署它们时,会出现如下错误:

结果:失败异常:ModuleNotFoundError:没有名为“azure.cosmosdb”的模块。疑难解答指南:Stack:File“/azure functions host/workers/python/3.8/LINUX/X64/azure\u functions\u worker/dispatcher.py”,第284行,在调用提升扩展异常消息中的第42行(e,message)文件“/azure functions host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py”,第40行,调用返回函数(*args,**kwargs)文件“/azure functions host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py”,第76行,在load_function mod=importlib.import_module(fullmodname)文件中“/usr/local/lib/python3.8/importlib/init.py”,第127行,在导入模块返回引导过程中。\u gcd\u导入(名称[level:],包,级别)文件“/home/site/wwwroot/user add/init.py”,第4行,从azure.cosmosdb.table.table导入表服务

我认为Azure端的Python环境似乎没有我在导入时指定的Azure,如下所示:

import logging

import azure.functions as func
import azure.cosmosdb.table
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity


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

    user_id = req.params.get('user_id')
    if not user_id:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            user_id = req_body.get('user_id')

    if user_id:

        the_connection_string = "redacted"
        table_service = TableService(endpoint_suffix="table.cosmos.azure.com",
                     connection_string=the_connection_string)

        # table_service.create_table('usertable')

        user = {"PartitionKey": "user",
                "RowKey": user_id}

        table_service.insert_entity('usertable', user)

        return func.HttpResponse(f"{user_id} added to the user database")

    else:
        return func.HttpResponse(
            "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
            status_code=200
        )


我不明白我需要做什么来强制他们安装一个同等的pip?这很疯狂,因为它应该是无服务器的?

请首先确保您已将
azure cosmos
添加到requirements.txt文件中


当您将Python azure函数部署到azure时,它将基于此文件安装模块。

您是否在requirements.txt中添加了所需的模块?