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

使用Zapier Code(Python)生成CSV字符串时遇str无copy属性错误求解

问题原因

该报错与CSV生成逻辑无关,是Zapier Python Code步骤的返回值规则限制导致:Zapier要求代码步骤必须返回字典类型的结果,平台底层会默认对返回结果调用copy()方法用于后续步骤的参数传递,你当前直接返回字符串类型的CSV内容,字符串对象本身没有copy()方法,就会触发该报错。

解决方案

把返回的CSV字符串封装到字典中返回即可,修改后代码如下:

import io
import csv
# root = ElementTree.fromstring(input_data['xml']);
stringio = io.StringIO()
fieldnames = ['first_name', 'last_name']
writer = csv.DictWriter(stringio, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
# 将CSV字符串封装为字典返回
return {'csv_content': stringio.getvalue()}

后续步骤需要用到生成的CSV内容时,直接取返回结果中的csv_content字段即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.11 02:30:01