End of script output before headers error with Python Script












1















I've read multiple SO posts regarding this, but can't seem to get this to work. This is my first time working with Python on Apache so I would appreciate the help I can get!



So ultimately, I'm trying to run a Python script in my htdocs, but I can't seem to just get the simple python script running on XAMPP. I keep getting a 500 error:



error



myurl.py



#!/usr/bin/env python3

print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Hello, world!
"""
)









share|improve this question























  • try replacing the first line with print("Content-type: text/htmlnn")

    – Madison Courto
    Nov 20 '18 at 22:42













  • @MadisonCourto I tried replacing it and it didn't help

    – Sam
    Nov 20 '18 at 22:45











  • @Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

    – Rob Bricheno
    Nov 20 '18 at 22:47











  • @RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

    – Sam
    Nov 20 '18 at 22:50











  • @RobBricheno it seems like I don't have the correct permissions right? how do I change that?

    – Sam
    Nov 20 '18 at 22:50


















1















I've read multiple SO posts regarding this, but can't seem to get this to work. This is my first time working with Python on Apache so I would appreciate the help I can get!



So ultimately, I'm trying to run a Python script in my htdocs, but I can't seem to just get the simple python script running on XAMPP. I keep getting a 500 error:



error



myurl.py



#!/usr/bin/env python3

print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Hello, world!
"""
)









share|improve this question























  • try replacing the first line with print("Content-type: text/htmlnn")

    – Madison Courto
    Nov 20 '18 at 22:42













  • @MadisonCourto I tried replacing it and it didn't help

    – Sam
    Nov 20 '18 at 22:45











  • @Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

    – Rob Bricheno
    Nov 20 '18 at 22:47











  • @RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

    – Sam
    Nov 20 '18 at 22:50











  • @RobBricheno it seems like I don't have the correct permissions right? how do I change that?

    – Sam
    Nov 20 '18 at 22:50
















1












1








1








I've read multiple SO posts regarding this, but can't seem to get this to work. This is my first time working with Python on Apache so I would appreciate the help I can get!



So ultimately, I'm trying to run a Python script in my htdocs, but I can't seem to just get the simple python script running on XAMPP. I keep getting a 500 error:



error



myurl.py



#!/usr/bin/env python3

print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Hello, world!
"""
)









share|improve this question














I've read multiple SO posts regarding this, but can't seem to get this to work. This is my first time working with Python on Apache so I would appreciate the help I can get!



So ultimately, I'm trying to run a Python script in my htdocs, but I can't seem to just get the simple python script running on XAMPP. I keep getting a 500 error:



error



myurl.py



#!/usr/bin/env python3

print("Content-Type: text/html")
print()
print ("""
<TITLE>CGI script ! Python</TITLE>
<H1>This is my first CGI script</H1>
Hello, world!
"""
)






python xampp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 22:39









SamSam

170111




170111













  • try replacing the first line with print("Content-type: text/htmlnn")

    – Madison Courto
    Nov 20 '18 at 22:42













  • @MadisonCourto I tried replacing it and it didn't help

    – Sam
    Nov 20 '18 at 22:45











  • @Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

    – Rob Bricheno
    Nov 20 '18 at 22:47











  • @RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

    – Sam
    Nov 20 '18 at 22:50











  • @RobBricheno it seems like I don't have the correct permissions right? how do I change that?

    – Sam
    Nov 20 '18 at 22:50





















  • try replacing the first line with print("Content-type: text/htmlnn")

    – Madison Courto
    Nov 20 '18 at 22:42













  • @MadisonCourto I tried replacing it and it didn't help

    – Sam
    Nov 20 '18 at 22:45











  • @Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

    – Rob Bricheno
    Nov 20 '18 at 22:47











  • @RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

    – Sam
    Nov 20 '18 at 22:50











  • @RobBricheno it seems like I don't have the correct permissions right? how do I change that?

    – Sam
    Nov 20 '18 at 22:50



















try replacing the first line with print("Content-type: text/htmlnn")

– Madison Courto
Nov 20 '18 at 22:42







try replacing the first line with print("Content-type: text/htmlnn")

– Madison Courto
Nov 20 '18 at 22:42















@MadisonCourto I tried replacing it and it didn't help

– Sam
Nov 20 '18 at 22:45





@MadisonCourto I tried replacing it and it didn't help

– Sam
Nov 20 '18 at 22:45













@Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

– Rob Bricheno
Nov 20 '18 at 22:47





@Sam Check out the error log written by Apache. It will give you more information about exactly what caused the 500 error. It's usually stored somewhere like /var/log/apache2/error.log

– Rob Bricheno
Nov 20 '18 at 22:47













@RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

– Sam
Nov 20 '18 at 22:50





@RobBricheno [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client ::1:50462] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed: /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20 17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End of script output before headers: myurl.py

– Sam
Nov 20 '18 at 22:50













@RobBricheno it seems like I don't have the correct permissions right? how do I change that?

– Sam
Nov 20 '18 at 22:50







@RobBricheno it seems like I don't have the correct permissions right? how do I change that?

– Sam
Nov 20 '18 at 22:50














1 Answer
1






active

oldest

votes


















2














As per the discussion, there were multiple problems here, which were solved by examining the error.log written by apache and then making appropriate changes.



The first error was:




[Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client
::1:50462] AH01215: (13)Permission denied: exec of
'/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed:
/Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End
of script output before headers: myurl.py




The relevant part here is:



(13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed


Permissions needed to be set on the .py file being executed to allow the user running the apache process to execute the script. This was done using chmod.



Then, another error was presented:




[Tue Nov 20 17:59:04.720816 2018] [cgi:error] [pid 48715] [client
::1:50555] AH01215: python3: No such file or directory:
/Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
17:59:04.720884 2018] [cgi:error] [pid 48715] [client ::1:50555] End
of script output before headers: myurl.py




The relevant part is:



python3: No such file or directory


This shows that the system could not find a python3 binary to execute. The correct path to the python3 interpreter had to be determined using which python3. This was then edited into the shebang line of the script.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402670%2fend-of-script-output-before-headers-error-with-python-script%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    As per the discussion, there were multiple problems here, which were solved by examining the error.log written by apache and then making appropriate changes.



    The first error was:




    [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client
    ::1:50462] AH01215: (13)Permission denied: exec of
    '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed:
    /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
    17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End
    of script output before headers: myurl.py




    The relevant part here is:



    (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed


    Permissions needed to be set on the .py file being executed to allow the user running the apache process to execute the script. This was done using chmod.



    Then, another error was presented:




    [Tue Nov 20 17:59:04.720816 2018] [cgi:error] [pid 48715] [client
    ::1:50555] AH01215: python3: No such file or directory:
    /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
    17:59:04.720884 2018] [cgi:error] [pid 48715] [client ::1:50555] End
    of script output before headers: myurl.py




    The relevant part is:



    python3: No such file or directory


    This shows that the system could not find a python3 binary to execute. The correct path to the python3 interpreter had to be determined using which python3. This was then edited into the shebang line of the script.






    share|improve this answer






























      2














      As per the discussion, there were multiple problems here, which were solved by examining the error.log written by apache and then making appropriate changes.



      The first error was:




      [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client
      ::1:50462] AH01215: (13)Permission denied: exec of
      '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed:
      /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
      17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End
      of script output before headers: myurl.py




      The relevant part here is:



      (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed


      Permissions needed to be set on the .py file being executed to allow the user running the apache process to execute the script. This was done using chmod.



      Then, another error was presented:




      [Tue Nov 20 17:59:04.720816 2018] [cgi:error] [pid 48715] [client
      ::1:50555] AH01215: python3: No such file or directory:
      /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
      17:59:04.720884 2018] [cgi:error] [pid 48715] [client ::1:50555] End
      of script output before headers: myurl.py




      The relevant part is:



      python3: No such file or directory


      This shows that the system could not find a python3 binary to execute. The correct path to the python3 interpreter had to be determined using which python3. This was then edited into the shebang line of the script.






      share|improve this answer




























        2












        2








        2







        As per the discussion, there were multiple problems here, which were solved by examining the error.log written by apache and then making appropriate changes.



        The first error was:




        [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client
        ::1:50462] AH01215: (13)Permission denied: exec of
        '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed:
        /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
        17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End
        of script output before headers: myurl.py




        The relevant part here is:



        (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed


        Permissions needed to be set on the .py file being executed to allow the user running the apache process to execute the script. This was done using chmod.



        Then, another error was presented:




        [Tue Nov 20 17:59:04.720816 2018] [cgi:error] [pid 48715] [client
        ::1:50555] AH01215: python3: No such file or directory:
        /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
        17:59:04.720884 2018] [cgi:error] [pid 48715] [client ::1:50555] End
        of script output before headers: myurl.py




        The relevant part is:



        python3: No such file or directory


        This shows that the system could not find a python3 binary to execute. The correct path to the python3 interpreter had to be determined using which python3. This was then edited into the shebang line of the script.






        share|improve this answer















        As per the discussion, there were multiple problems here, which were solved by examining the error.log written by apache and then making appropriate changes.



        The first error was:




        [Tue Nov 20 17:49:06.593901 2018] [cgi:error] [pid 47854] [client
        ::1:50462] AH01215: (13)Permission denied: exec of
        '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed:
        /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
        17:49:06.595547 2018] [cgi:error] [pid 47854] [client ::1:50462] End
        of script output before headers: myurl.py




        The relevant part here is:



        (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/myurl.py' failed


        Permissions needed to be set on the .py file being executed to allow the user running the apache process to execute the script. This was done using chmod.



        Then, another error was presented:




        [Tue Nov 20 17:59:04.720816 2018] [cgi:error] [pid 48715] [client
        ::1:50555] AH01215: python3: No such file or directory:
        /Applications/XAMPP/xamppfiles/htdocs/myurl.py [Tue Nov 20
        17:59:04.720884 2018] [cgi:error] [pid 48715] [client ::1:50555] End
        of script output before headers: myurl.py




        The relevant part is:



        python3: No such file or directory


        This shows that the system could not find a python3 binary to execute. The correct path to the python3 interpreter had to be determined using which python3. This was then edited into the shebang line of the script.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 23:39

























        answered Nov 20 '18 at 23:34









        Rob BrichenoRob Bricheno

        2,325218




        2,325218






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402670%2fend-of-script-output-before-headers-error-with-python-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy