When I try to test my python function in Lambda, I'm getting this error below:
"errorMessage": "Syntax error in module 'lambda_function'"
And this error in the CloudWatch logs:
Syntax error in module 'lambda_function': unexpected unindent (lambda_function.py, line 28)
Here is my python code:
from __future__ import print_function
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
import hashlib
import datetime
import json
print('Loading function')
def my_urlopen(url):
try:
return urllib2.urlopen(url)
except Exception as e:
try:
return urllib2.urlopen(url)
except Exception as e2:
urllib2.urlopen("https://example.com/cron/error.php?url="+url+"&code="+str(e2.code));#+"&reason="+e2.reason);
return None
return None
def customer_list(cron_cipher, minute):
try:
return urllib2.urlopen("https://d-example.com:444/TESTcron.php?k="+cron_cipher+"&m="+minute+"&f=rules")
except Exception as e:
try:
return urllib2.urlopen("https://e-example.com:444/TESTcron.php?k="+cron_cipher+"&m="+minute+"&f=rules")
except Exception as e2:
urllib2.urlopen("https://example.com/cron/error.php?url="+url+"&code="+str(e2.code))
print("Lookup error: https://example.com/cron/error.php?url="+url+"&code="+str(e2.code));
return None
return None
def lambda_handler(event, context):
# code continues below....
I'm extremely new to python, but the code was working using the my_urlopen function as it shows here, but the addition of the customer_list function seems to be causing a problem, though I cannot see the syntax issue.
Line 28 is the except Exception as e2: line in the customer_list function.
It appears to be indented the correct amount, and I think the semicolons aren't needed (though I have tried both with and without). What am I missing?
