2

I am trying to run a python script on page load. The python script will save a log.text file with some log information. After doing some research I came up with:

    <script>
    window.onload = function () {
        $.ajax({
            type: 'POST',
            url: "img/test.py",
            success: function () {
                alert("working")
            },
            error: function () {
                alert("Not Working")
            }
        });
    };
</script>

Which works, everytime the page loads it alerts me that it was successful. And here is test.py:

#!/usr/local/bin/env python

try:
    txt = open(r'log.txt', "wb")
    txt.write("Success")
    txt.close()
except Exception,e:
    txt = open(r'log.txt', "wb")
    txt.write(e)
    txt.close()

But this is where the problem is. The file is not created and I don't know why.

More information: I am using godaddy as a hosting service. My script is written in python2.6. When I ssh in and use:

$ python path_to_file/test.py

It creates the file in the current cd location. So the server can run the file with python but when i use:

$ cd path_to_file
$ ./test.py

I get:

-bash: ./test.py: Permission denied

Is that a problem or is this normal? Everything else works I just seem to be missing one piece of this puzzle. Is my shebang statement correct? Why does my process not generate a log.txt file?

1
  • 1
    Aren't you just reading the contents of the python script via ajax? If you change success: function () { alert("working") } to success: function (data) { alert(data) } and see the python code, it's not being executed. Commented Jun 26, 2016 at 21:38

1 Answer 1

2

Did you set the execution flag on that file?

  chmod +x test.py  

should do…

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.