Python code in Zapier (invalid syntax (usercode.py, line 42))









up vote
0
down vote

favorite












This code is pre-made in a Zapier forum to pull failed responses from another piece of software called iAuditor. When I plug in the code and update the API token and webhook URL this error pops up:



Traceback (most recent call last):
SyntaxError: invalid syntax (usercode.py, line 42)



Here is the code:



[code]

import json
import requests

auth_header = 'Authorization': 'a4fca847d3f203bd7306ef5d1857ba67a2b3d66aa455e06fac0ad0be87b9d226'
webhook_url = 'https://hooks.zapier.com/hooks/catch/3950922/efka9n/'
api_url = 'https://api.safetyculture.io/audits/'
audit_id = input['audit_id']
audit_doc = requests.get(api_url + audit_id, headers=auth_header).json()
failed_items =
audit_author = audit_doc['audit_data']['authorship']['author']
conducted_on = audit_doc['audit_data']['date_completed']
conducted_on = conducted_on[:conducted_on.index('T')]
audit_title = audit_doc['template_data']['metadata']['name']
for item in audit_doc['items']:
if item.get('responses') and item['responses'].get('failed') == True:
label = item.get('label')
if label is None:
label = 'no_label'
responses = item['responses']
response_label = responses['selected'][0]['label']
notes = responses.get('text')
if notes is None:
notes = ''
failed_items.append('label': label,
'response_label': response_label,
'conducted_on': conducted_on,
'notes': notes,
'author': audit_author
)
for item in failed_items:
r = requests.post(webhook_url, data = item)
return response.json()
[/code]









share|improve this question





















  • Your code has length 32 lines and the error appears in line 42....
    – sophros
    Nov 8 at 16:14










  • Yes I noticed that. Any idea what would cause that to happen?
    – John Daggett
    Nov 8 at 16:20










  • Maybe you copied a different file than actually the one with the error?
    – sophros
    Nov 8 at 16:24










  • No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
    – John Daggett
    Nov 8 at 16:27










  • I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
    – John Daggett
    Nov 8 at 16:35















up vote
0
down vote

favorite












This code is pre-made in a Zapier forum to pull failed responses from another piece of software called iAuditor. When I plug in the code and update the API token and webhook URL this error pops up:



Traceback (most recent call last):
SyntaxError: invalid syntax (usercode.py, line 42)



Here is the code:



[code]

import json
import requests

auth_header = 'Authorization': 'a4fca847d3f203bd7306ef5d1857ba67a2b3d66aa455e06fac0ad0be87b9d226'
webhook_url = 'https://hooks.zapier.com/hooks/catch/3950922/efka9n/'
api_url = 'https://api.safetyculture.io/audits/'
audit_id = input['audit_id']
audit_doc = requests.get(api_url + audit_id, headers=auth_header).json()
failed_items =
audit_author = audit_doc['audit_data']['authorship']['author']
conducted_on = audit_doc['audit_data']['date_completed']
conducted_on = conducted_on[:conducted_on.index('T')]
audit_title = audit_doc['template_data']['metadata']['name']
for item in audit_doc['items']:
if item.get('responses') and item['responses'].get('failed') == True:
label = item.get('label')
if label is None:
label = 'no_label'
responses = item['responses']
response_label = responses['selected'][0]['label']
notes = responses.get('text')
if notes is None:
notes = ''
failed_items.append('label': label,
'response_label': response_label,
'conducted_on': conducted_on,
'notes': notes,
'author': audit_author
)
for item in failed_items:
r = requests.post(webhook_url, data = item)
return response.json()
[/code]









share|improve this question





















  • Your code has length 32 lines and the error appears in line 42....
    – sophros
    Nov 8 at 16:14










  • Yes I noticed that. Any idea what would cause that to happen?
    – John Daggett
    Nov 8 at 16:20










  • Maybe you copied a different file than actually the one with the error?
    – sophros
    Nov 8 at 16:24










  • No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
    – John Daggett
    Nov 8 at 16:27










  • I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
    – John Daggett
    Nov 8 at 16:35













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This code is pre-made in a Zapier forum to pull failed responses from another piece of software called iAuditor. When I plug in the code and update the API token and webhook URL this error pops up:



Traceback (most recent call last):
SyntaxError: invalid syntax (usercode.py, line 42)



Here is the code:



[code]

import json
import requests

auth_header = 'Authorization': 'a4fca847d3f203bd7306ef5d1857ba67a2b3d66aa455e06fac0ad0be87b9d226'
webhook_url = 'https://hooks.zapier.com/hooks/catch/3950922/efka9n/'
api_url = 'https://api.safetyculture.io/audits/'
audit_id = input['audit_id']
audit_doc = requests.get(api_url + audit_id, headers=auth_header).json()
failed_items =
audit_author = audit_doc['audit_data']['authorship']['author']
conducted_on = audit_doc['audit_data']['date_completed']
conducted_on = conducted_on[:conducted_on.index('T')]
audit_title = audit_doc['template_data']['metadata']['name']
for item in audit_doc['items']:
if item.get('responses') and item['responses'].get('failed') == True:
label = item.get('label')
if label is None:
label = 'no_label'
responses = item['responses']
response_label = responses['selected'][0]['label']
notes = responses.get('text')
if notes is None:
notes = ''
failed_items.append('label': label,
'response_label': response_label,
'conducted_on': conducted_on,
'notes': notes,
'author': audit_author
)
for item in failed_items:
r = requests.post(webhook_url, data = item)
return response.json()
[/code]









share|improve this question













This code is pre-made in a Zapier forum to pull failed responses from another piece of software called iAuditor. When I plug in the code and update the API token and webhook URL this error pops up:



Traceback (most recent call last):
SyntaxError: invalid syntax (usercode.py, line 42)



Here is the code:



[code]

import json
import requests

auth_header = 'Authorization': 'a4fca847d3f203bd7306ef5d1857ba67a2b3d66aa455e06fac0ad0be87b9d226'
webhook_url = 'https://hooks.zapier.com/hooks/catch/3950922/efka9n/'
api_url = 'https://api.safetyculture.io/audits/'
audit_id = input['audit_id']
audit_doc = requests.get(api_url + audit_id, headers=auth_header).json()
failed_items =
audit_author = audit_doc['audit_data']['authorship']['author']
conducted_on = audit_doc['audit_data']['date_completed']
conducted_on = conducted_on[:conducted_on.index('T')]
audit_title = audit_doc['template_data']['metadata']['name']
for item in audit_doc['items']:
if item.get('responses') and item['responses'].get('failed') == True:
label = item.get('label')
if label is None:
label = 'no_label'
responses = item['responses']
response_label = responses['selected'][0]['label']
notes = responses.get('text')
if notes is None:
notes = ''
failed_items.append('label': label,
'response_label': response_label,
'conducted_on': conducted_on,
'notes': notes,
'author': audit_author
)
for item in failed_items:
r = requests.post(webhook_url, data = item)
return response.json()
[/code]






python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 16:11









John Daggett

1




1











  • Your code has length 32 lines and the error appears in line 42....
    – sophros
    Nov 8 at 16:14










  • Yes I noticed that. Any idea what would cause that to happen?
    – John Daggett
    Nov 8 at 16:20










  • Maybe you copied a different file than actually the one with the error?
    – sophros
    Nov 8 at 16:24










  • No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
    – John Daggett
    Nov 8 at 16:27










  • I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
    – John Daggett
    Nov 8 at 16:35

















  • Your code has length 32 lines and the error appears in line 42....
    – sophros
    Nov 8 at 16:14










  • Yes I noticed that. Any idea what would cause that to happen?
    – John Daggett
    Nov 8 at 16:20










  • Maybe you copied a different file than actually the one with the error?
    – sophros
    Nov 8 at 16:24










  • No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
    – John Daggett
    Nov 8 at 16:27










  • I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
    – John Daggett
    Nov 8 at 16:35
















Your code has length 32 lines and the error appears in line 42....
– sophros
Nov 8 at 16:14




Your code has length 32 lines and the error appears in line 42....
– sophros
Nov 8 at 16:14












Yes I noticed that. Any idea what would cause that to happen?
– John Daggett
Nov 8 at 16:20




Yes I noticed that. Any idea what would cause that to happen?
– John Daggett
Nov 8 at 16:20












Maybe you copied a different file than actually the one with the error?
– sophros
Nov 8 at 16:24




Maybe you copied a different file than actually the one with the error?
– sophros
Nov 8 at 16:24












No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
– John Daggett
Nov 8 at 16:27




No, this is the only piece of python code I have ever dealt with. This error is coming from this code.
– John Daggett
Nov 8 at 16:27












I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
– John Daggett
Nov 8 at 16:35





I removed the [code] and [/code] and now am getting this error: Traceback (most recent call last): File "/tmp/tmpLu46ym/usercode.py", line 16, in the_function audit_author = audit_doc['audit_data']['authorship']['author'] KeyError: 'audit_data'
– John Daggett
Nov 8 at 16:35













1 Answer
1






active

oldest

votes

















up vote
0
down vote













This looks like an error from the platform. It looks like Zapier uses a script called usercode.py to bootstrap launching your script and the error seems to be coming from that part.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211728%2fpython-code-in-zapier-invalid-syntax-usercode-py-line-42%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This looks like an error from the platform. It looks like Zapier uses a script called usercode.py to bootstrap launching your script and the error seems to be coming from that part.






    share|improve this answer
























      up vote
      0
      down vote













      This looks like an error from the platform. It looks like Zapier uses a script called usercode.py to bootstrap launching your script and the error seems to be coming from that part.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        This looks like an error from the platform. It looks like Zapier uses a script called usercode.py to bootstrap launching your script and the error seems to be coming from that part.






        share|improve this answer












        This looks like an error from the platform. It looks like Zapier uses a script called usercode.py to bootstrap launching your script and the error seems to be coming from that part.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 16:34









        sophros

        1,5981418




        1,5981418



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211728%2fpython-code-in-zapier-invalid-syntax-usercode-py-line-42%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)