使用python进行Zapier行项目操作

时间:2018-03-14 21:14:28

标签: python zapier

我的zap从内部通信运行GET,它将一个convo中的所有消息放入一个行项目字段。

我想将整个订单项字段更改为字符串,而不包含zapier在加入所有值时输入的所有逗号。所以我可以把对话写成其他地方的文字说明。

zapier的某个人建议我应该使用代码中的join来执行此操作,但是当然他们不能给我实际的代码。

输入:

input_data = {
    "values": "<p>Ok, I see your request. Give me just a minute to get it set up </p>,<p>ok</p>,<p>You should see the email shortly. When you get logged in, let me know if you have any other questions, I'm happy to help </p>,<p>cool</p>,<p>More Pipedrive testing</p>"
}

我尝试了以下代码:

L = input_data['values']  
return {" ".join(str(x) for x in L)}

但是出现了以下错误:

TypeError(repr(o) + " is not JSON serializable") 
TypeError: set(['< p > H i n e w b i e < / p >']) is not JSON serializable

1 个答案:

答案 0 :(得分:0)

酷!所以你的问题是你从代码步骤返回一个python set,而Zapier不能将其变成json。

发生了这种情况,因为你在curlies之间有一个字符串。参见:

>>> {'asdf'}
set(['asdf'])

您的输入是一个包含html的大字符串。您好像可以在</p>,<p>上分开并加入' '

在任何一种情况下,您都需要将输出作为值返回:

>>> {'result': " ".join(str(x) for x in L.split('</p>,<p>'))}
{'result': "<p>Ok, I see your request. Give me just a minute to get it set up  ok You should see the email shortly. When you get logged in, let me know if you have any other questions, I'm happy to help  cool More Pipedrive testing</p>"}

如果您愿意,还可以提取前导<p>标记。

希望有所帮助!