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]
python
add a comment |
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]
python
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
add a comment |
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]
python
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
python
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 8 at 16:34
sophros
1,5981418
1,5981418
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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