You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向Azure上传Blob时触发TypeError: quote_from_bytes() expected bytes错误

Python上传Azure Blob报错:TypeError: quote_from_bytes() expected bytes

错误原因

这个错误是因为设置Blob标签时传入了非字符串类型的标签值。Azure存储SDK在序列化Blob标签时,会调用urllib.parse.quote处理标签值,若值是数字、布尔值、None这类非字符串类型,就会触发该类型错误。

解决方法

  • 确保所有Blob标签的值都为字符串类型,非字符串值需显式转换:
    # 错误示例:标签值为非字符串类型
    blob_tags = {"file_type": 1, "processed": True}
    blob_client.set_blob_tags(blob_tags)
    
    # 修正后:将所有值转为字符串
    blob_tags = {"file_type": "1", "processed": "True"}
    blob_client.set_blob_tags(blob_tags)
    
  • 若标签值可能为None,提前处理为合理字符串(比如空字符串),避免传入None。

完整错误日志

File "C:\Users\P3159331\OneDrive - Charter Communications\Documents - Audience Insights\5. Development\nielsen_full\devenv\lib\site-packages\azure\storage\blob_serialize.py", line 170, in serialize_blob_tags_header
components.append(quote(value, safe='.-'))
File "C:\Users\P3159331\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 869, in quote
return quote_from_bytes(string, safe)
File "C:\Users\P3159331\AppData\Local\Programs\Python\Python310\lib\urllib\parse.py", line 894, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes

内容的提问来源于stack exchange,提问作者Jack Driscoll

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 01:52:07