0

I have a web application that runs over a Centos Server. It was written in php and python. Suddenly without modification something starts to works in alternate and randomly way (one time fileB.php is called, one time not). I'll try to explain this problem better... This is the application flow:

fileA.php (fileA.php calls filePy.py by an exec command) -> filePY.py (it sends 5 mails and then calls fileB.php) -> fileB.php declare this process close

this is filePY.py:

# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import smtplib
import subprocess

#cmdargs comes from fileA.php
val1 = cmdargs[1] 
subject = cmdargs[2]
toAddress = cmdargs[3]
mailText = cmdargs[4]
attachment = cmdargs[5]
fromAddress = cmdargs[6]


i = 0
while (i < 5):
    i+=1
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = fromAddress
    msg['To'] = toAddress
    # That is what u see if dont have an email reader:
    msg.preamble = 'Multipart massage.\n'

    # This is the textual part:
    part = MIMEText(mailText)
    msg.attach(part)

    # This is the binary part(The Attachment):
    if attachment:
        part = MIMEApplication(open(attachment,"rb").read())
        part.add_header('Content-Disposition', 'attachment', filename=attachment)
        msg.attach(part)


    server = smtplib.SMTP_SSL('stmp-server',port)
    server.login(fromAddress, 'password')
    server.set_debuglevel(1)
    server.sendmail(fromAddress, [toAddress], msg.as_string())
    server.quit()

#call a php file and send val1 as parameter 
cmd = 'php -f fileB.php '+val1
subprocess.call(cmd, shell=True)

So what's the error? Suddenly the last part of the python file seems that isn't execute, this is the file's part:

#call a php file and send val1 as parameter 
cmd = 'php -f fileB.php '+val1
subprocess.call(cmd, shell=True)

Our server provider tells that no update was deployed on our machine. I can exclude any code related problems because there's no update or modifications. We can't find a reasons to that behaviour... So my question is , can someone suggest me something in server that can cause an alternate behaviour like this? I know that is a too much generic question but what i need is only a general suggestion that help me to investigate better the problem.

We have also set and reads a python.log but i can't print/see anything interesting. Please tell me if i have to place more server's details.

  • Your developers should do error checking and capture stdout/stderr. For help debugging your program, please visit our sister site Stack Overflow. – Michael Hampton Jan 30 at 18:17
  • My guess is that a Python exception is being raised earlier in the script, maybe when you try and authenticate against the SMTP server (if the back end authentication mechanism is flakey, LDAP perhaps, where it doesn't authenticate quickly enough, etc). Python will exit with a non-zero exit code and the final end of the script will not be executed. fileA.php should be checking for a non-zero exit code from execution of filePY.py also. If you are relying on scripts calling other scripts like this, you really need to be checking exit codes for sure. – parkamark Jan 30 at 19:34

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.