7

I have made a very simple Python helper, to update a task in Asana with custom field on a task. it works on my local machine in terminal.

I am trying to add it to a Zapier 'Run Python' block, but get what looks like a generic error 'str' object has no attribute 'copy'

Here's the Python code which I'd appreciate any advice on why it wont run in a "Run Python" module in Zapier -- there's no str in these lines!!?

import requests

headers = {'Authorization':'Bearer 1/xxxxx'}
task_id = input_data['task_id']
data = {"data": {"custom_fields": {"1200278184463303":"#" + input_data['row_number']}}}

response = requests.put('https://app.asana.com/api/1.0/tasks/' + task_id, headers=headers, json=data)

return 'task #' + input_data['row_number'] + 'assigned'
6
  • Did you forget to include the relevant code block? Commented May 3, 2021 at 15:20
  • You need to include the reproducable code. However, the error is self explanatory. You are trying to run a function, copy, on a variable that has a string value and not an object value. Commented May 3, 2021 at 15:22
  • @JustinOberle thats the entire code! it works in Visual Studio terminal, and my OS X terminal. Zapier tells me to start a "Run Python" code block as a step -- and to paste my code in there. im not trying to run any copy function. i guess Zapiers parser is? zapier.com/help/create/code-webhooks/use-python-code-in-zaps Commented May 3, 2021 at 15:33
  • There is no possible way that is the entire code. When I copy and paste it into my editor I have syntax errors on basically every line saying certain things are not defined. for example, where is input_data defined? Commented May 3, 2021 at 15:36
  • 1
    I appreciate your replies but i am following this advice from the Zapier guide; If you encounter a problem, we recommend asking questions on StackOverflow and tagging them with "Zapier". Seems you're not familiar with the Zapier code block "Run Python". The input_data[] comes from that. Commented May 3, 2021 at 15:54

2 Answers 2

13

I realize this is answered, but I wanted to add some context. Code by Zapier steps expect a dict to be returned; you're returning a string.

Zapier should throw a more explicit error here (something like "expected dict, got str"), but isn't. Instead, it's calling .copy() on the output, which results in the error you're seeing:

>>> {}.copy()
{}

>>> ''.copy()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'copy'

'str' object has no attribute 'copy'

There are two options to fix it:

  1. Set a key on the pre-defined output dict (the currently accepted answer)
  2. Manually return a dict: return {'field_name': 'task #' + input_data['row_number'] + 'assigned'}

Either will work here.

Sign up to request clarification or add additional context in comments.

2 Comments

came back to my question as I was having trouble with another "Run Code" Python / Zapier block, this helped me even more this time, thansk very much David
Glad to hear it!
3

I had better luck with the following syntax (with your code in place):

output['outputfieldname'] = 'task #' + input_data['row_number'] + 'assigned'

1 Comment

thanks so much. the Asana guide for this module should be much clearer about the necessity for an output variable!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.