zapier

"Run Python" module gives error: 'str' object has no attribute 'copy'


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'

Solution

  • 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.