【问题标题】:unable to encode outgoing TypedData: unsupported type "<class 'azure_functions_worker.bindings.generic.GenericBinding'>" for Python type "DataFrame"无法编码传出 TypedData:Python 类型 \"DataFrame\" 的不支持类型 \"<class \'azure_functions_worker.bindings.generic.GenericBinding\'>\"
【发布时间】:2022-08-04 17:56:30
【问题描述】:

我正在尝试通过 SAS 密钥上传我访问过的文件,并且我已经清理到 azure Blob Storage。如您所见,我为此使用了 BlobTrigger。我无法弄清楚如何处理此错误或如何将其转换为 DataFrame(我已经尝试转换为 Panda 数据帧)。我也读过Microsoft Docs,也许我错过了一点。

我得到的错误:

失败异常:TypeError:无法编码传出 TypedData:Python 类型 \"DataFrame\" 的不支持类型 \"<class \'azure_functions_worker.bindings.generic.GenericBinding\'>\"

基本上我正在读取一个 Excel 文件,我想将 Excel 文件写回另一个容器。

Function.Json 文件:

{
 \"scriptFile\": \"__init__.py\",
  \"bindings\": [
    {
      \"name\": \"myblob\",
      \"type\": \"blobTrigger\",
      \"direction\": \"in\",
      \"path\": \"input/{name}.xlsx\",
      \"connection\": \"AzureWebJobsStorage\"
    },
    {
      \"name\": \"outputblob\",
      \"type\": \"blob\",
      \"path\": \"output/{name}\",
      \"connection\": \"AzureWebJobsStorage\",
      \"direction\": \"out\"
    }
  ],
  \"disabled\": false
}

在里面.py 文件:

def main(myblob: func.InputStream, outputblob: func.Out[bytes]):
  def read_excel_files(_container, _filename):
      sas = generate_SAS(f\"{_container}\", f\"{_filename}\")
      blob_url = f\'https://{account_name}.blob.core.windows.net/{_container}/{_filename}?{sas}\'
      return pd.read_excel(blob_url)

  if myblob.name.__contains__(\"Book\"):
      logging.info(\"Book was found\")
      Buch = read_excel_files(\"_container\", \"_filename.xlsx\")
      logging.info(\"Starting cleaning Process\")
      ...
      logging.info(\"Cleaning is finished\")        
      outputblob.set(Buch)

    标签: python pandas azure file-io azure-functions


    【解决方案1】:

    如另一个Questionlinked Code 中所述,我必须将字符串作为字符串上传到Azure。 我只发布了我更改的部分代码。

    outputblob: func.Out[str]) -> None:
    
     #everything is the same
     #Change the your variable to string before uploading
     outputblob.set(Buch.to_string())
    

    【讨论】:

      猜你喜欢
      • 2021-06-02
      • 2022-11-11
      • 2016-12-27
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 1970-01-01
      • 2012-04-21
      相关资源
      最近更新 更多