Hi, I'm trying send am email notification through Python script by using Fault and script policies. But there are few errors at the time of deployment If I'm changing mu code in target URL. I'm sure, I'm doing something wrong. I think, we are not suppose to add python script in fault flow. If that is true, where we can add the condition that if I got 403 response code then I need to send an email notification. Can anyone please help me fixing this?
Working: targets->default.xml:
<FaultRules> <FaultRule name="401_Errors"> <Step> <Name>Raise-Fault-1</Name> <Condition>(response.status.code = 403) or (response.status.code = 301) or (response.status.code = 405) or (response.status.code = 404)</Condition> </Step> </FaultRule> <FaultRule name="target_not_reachable"> <Step> <Name>Return502</Name> </Step> </FaultRule> </FaultRules>
Not Working: targets->default.xml:
<FaultRules> <FaultRule name="401_Errors"> <Step> <Name>pythonscriptpolicy</Name> <Condition>(response.status.code = 403) or (response.status.code = 301) or (response.status.code = 405) or (response.status.code = 404)</Condition> </Step> </FaultRule> <FaultRule name="target_not_reachable"> <Step> <Name>Return502</Name> </Step> </FaultRule> </FaultRules>
Attached the proxy for reference. Thanks!
Solved! Go to Solution.
Hi @Swapna,
I did not go through your script but I created a small python script and deployed in my proxy and I am getting emails sent. The script I have is below :
import smtplib fromaddr = 'abcd@gmail.com' toaddrs = 'sarthak@apigee.com' msg = 'Why,Oh why! sending from EDGE' username = 'abcd@gmail.com' password = 'erfg4sdglvzubi' server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, msg) server.quit()
Let me know if you still see the error