Fault handling for Responses codes

Not applicable

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 Solved
0 7 848
1 ACCEPTED SOLUTION

sarthak
Participant V

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

View solution in original post

7 REPLIES 7

Not applicable

Hi @Swapna ,

py scripts in fault handling works .I have done that earlier and there are no issues with that .

I don't see any issue with the above non working snippet and looked at your policy too. Can you try the below by adding all the attributes , I don't think thats an issue but the below is working for me

<Script name="AssignRatelimitError" timeLimit="0" enabled="true" continueOnError="false" async="false">

<ResourceURL>py://AssignRatelimitError.py</ResourceURL>

</Script>

sarthak
Participant V

Hi @Swapna

Me like @Maruti Chand also do not see the error. I deployed the proxy and everything works fine.

One comment about your specific proxy though is : The target URL which you are using is from twitter , which do not give a 404/403 like probably what you are hoping for. It is returning a 301 error code.

By default Apigee treat 3XX codes as success and hence the response won't even go into fault flow. I changed the target to http://httpbin.org/hidden-basic-auth/user/passwd which gives me a 404 and it worked for me.

Thanks

sarthak
Participant V

BTW @Swapna your python script has logical problems.

host = flow.getVariable("smtp.gmail.com"); when you have this it means that you are trying to fetch the Value of a variable called smtp.gmail.com which is available as flow variable in the Apigee environment.

I am guessing you rather meant to do host = 'smtp.gmail.com' if you are not setting up the value of 'smtp.gmail.com' in some previous step (which I do not see in the proxy shared by you.)

Not applicable

Thank you @Maruti Chand and @sarthak

I did the modifications as per your suggestions but python script is giving the below error. Tried many ways to use the smtp server but no luck. Attached the same.

@sarthak I have tired by changing all the variables to host = 'smtp.gmail.com' format. But it is also not working fine.

Please help me on fixing this issue. Thanks!

Trace Error Log:

<Point id="Error"> -<DebugInfo> <Timestamp>31-07-15 15:14:39:363</Timestamp> -<Properties> <Property name="error.cause.cause">-NA-</Property> <Property name="error">Evaluation of script SendMail.py (py) failed with reason: "smtplib.SMTPException: SMTP AUTH extension not supported by server."</Property> <Property name="type">ErrorPoint</Property> <Property name="state">TARGET_RESP_FLOW</Property> <Property name="error.class">com.apigee.flow.FlowException</Property> <Property name="error.cause">smtplib.SMTPException: SMTP AUTH extension not supported by server. in SendMail.py at line number 34</Property> </Properties> </DebugInfo>

sarthak
Participant V

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

Did this work ?

Not applicable

Thanks @sarthak It worked for me now with the above script.