小编Rap*_*tus的帖子

尝试使用 python 从 azure 函数触发 url,错误提示“没有 $return 绑定返回了非 None 值”

下面是代码,

import logging
import json 
import urllib.request
import urllib.parse
import azure.functions as func


def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    response = urllib.request.urlopen("http://example.com:5000/processing")
    return {
        'statusCode': 200,
        'body': json.dumps(response.read().decode('utf-8'))
    }
Run Code Online (Sandbox Code Playgroud)

错误:结果:失败异常:RuntimeError:没有 $return 绑定的函数“abc”返回非 None 值堆栈:文件“/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py ",第 341 行,在 _handle__invocation_request f'function {fi.name!r} 中,没有 $return 绑定'。相同的代码可以在 lambda 中运行。请帮助我在 azure 函数中进行调试。

函数.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "sourcemetadata/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

python azure python-2.7 python-3.x

2
推荐指数
1
解决办法
2573
查看次数

使用Python中的Azure语音服务读取音频文件并转换为文本,但只有第一句话转换为语音

下面是代码,

import json
import os
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import azure.cognitiveservices.speech as speechsdk

def main(filename):
    container_name="test-container"
            print(filename)
    blob_service_client = BlobServiceClient.from_connection_string("DefaultEndpoint")
    container_client=blob_service_client.get_container_client(container_name)
    blob_client = container_client.get_blob_client(filename)
    with open(filename, "wb") as f:
        data = blob_client.download_blob()
        data.readinto(f)

    speech_key, service_region = "1234567", "eastus"
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

    audio_input = speechsdk.audio.AudioConfig(filename=filename)
    print("Audio Input:-",audio_input)
  
    speech_config.speech_recognition_language="en-US"
    speech_config.request_word_level_timestamps()
    speech_config.enable_dictation()
    speech_config.output_format = speechsdk.OutputFormat(1)

    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_input)
    print("speech_recognizer:-",speech_recognizer)
    #result = speech_recognizer.recognize_once()
    all_results = []

    def handle_final_result(evt):
        all_results.append(evt.result.text)  
    done = False 

    def stop_cb(evt):
        #print('CLOSING on {}'.format(evt))
        speech_recognizer.stop_continuous_recognition()
        global done …
Run Code Online (Sandbox Code Playgroud)

python speech-recognition azure speech-to-text python-3.x

2
推荐指数
1
解决办法
2225
查看次数

尝试创建 docker 容器功能应用程序,当我执行 docker run 时收到错误“未定义存储”

遵循微软文档(https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image?tabs=bash%2Cportal&pivots=programming-language-python)但是用于Azure Blob 存储触发器模板。

当我运行 docker run -p 8080:80 -it example/azurefunctionsimage:v1.0 时出现以下错误,

 fail: Host.Startup[402]
fail: Host.Startup[402]
      The 'voice-text' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.voice-text'. Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsStorage' does not exist. Make sure that it is a defined App Setting.
Hosting environment: Production
Content root path: /
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
info: Host.General[316]
      Host lock lease acquired by instance ID '0000000000000000000000000'.
warn: Microsoft.Azure.WebJobs.Script.ChangeAnalysis.ChangeAnalysisService[0]
      Breaking change analysis …
Run Code Online (Sandbox Code Playgroud)

azure docker azure-blob-storage azure-functions-core-tools azure-function-app

2
推荐指数
1
解决办法
873
查看次数