XAMPP apache setup on Windows to run .py Python files : ScriptInterpreterSource Registry-Strict












1















I've got my installation of the newest XAMPP version (w/PHP 7.2.2) setup and running apache just fine on my Windows 10 laptop for my PHP programming class. I was able to get CGI working to run .py files correctly in the browser window, using the option +ExecCGI and adding .py to the AddHandler line in the /XAMPP/apache/conf/httpd.conf.



Normally the first two lines need to look like this with CGI in order for the .py file to run correctly:



#!C:/Python/Python36_x86/python.exe
print("Content-Type: text/htmln")


However, after reading Apache2.4 documentation for ScriptInterpreterSource: https://httpd.apache.org/docs/2.4/mod/core.html#scriptinterpretersource



I added the correct registry key mentioned in the documentation along with the line:



ScriptInterpreterSource Registry-Strict


to my /XAMPP/apache/conf/httpd.conf



and was able to run my Python script without those first two lines. However, it still requires an extra print() statement on the first line (or print('n') ).



===========================================================================



MY QUESTION:



Is there any way at all to get around needing the print/newline statement on the first line of the Python script?










share|improve this question



























    1















    I've got my installation of the newest XAMPP version (w/PHP 7.2.2) setup and running apache just fine on my Windows 10 laptop for my PHP programming class. I was able to get CGI working to run .py files correctly in the browser window, using the option +ExecCGI and adding .py to the AddHandler line in the /XAMPP/apache/conf/httpd.conf.



    Normally the first two lines need to look like this with CGI in order for the .py file to run correctly:



    #!C:/Python/Python36_x86/python.exe
    print("Content-Type: text/htmln")


    However, after reading Apache2.4 documentation for ScriptInterpreterSource: https://httpd.apache.org/docs/2.4/mod/core.html#scriptinterpretersource



    I added the correct registry key mentioned in the documentation along with the line:



    ScriptInterpreterSource Registry-Strict


    to my /XAMPP/apache/conf/httpd.conf



    and was able to run my Python script without those first two lines. However, it still requires an extra print() statement on the first line (or print('n') ).



    ===========================================================================



    MY QUESTION:



    Is there any way at all to get around needing the print/newline statement on the first line of the Python script?










    share|improve this question

























      1












      1








      1








      I've got my installation of the newest XAMPP version (w/PHP 7.2.2) setup and running apache just fine on my Windows 10 laptop for my PHP programming class. I was able to get CGI working to run .py files correctly in the browser window, using the option +ExecCGI and adding .py to the AddHandler line in the /XAMPP/apache/conf/httpd.conf.



      Normally the first two lines need to look like this with CGI in order for the .py file to run correctly:



      #!C:/Python/Python36_x86/python.exe
      print("Content-Type: text/htmln")


      However, after reading Apache2.4 documentation for ScriptInterpreterSource: https://httpd.apache.org/docs/2.4/mod/core.html#scriptinterpretersource



      I added the correct registry key mentioned in the documentation along with the line:



      ScriptInterpreterSource Registry-Strict


      to my /XAMPP/apache/conf/httpd.conf



      and was able to run my Python script without those first two lines. However, it still requires an extra print() statement on the first line (or print('n') ).



      ===========================================================================



      MY QUESTION:



      Is there any way at all to get around needing the print/newline statement on the first line of the Python script?










      share|improve this question














      I've got my installation of the newest XAMPP version (w/PHP 7.2.2) setup and running apache just fine on my Windows 10 laptop for my PHP programming class. I was able to get CGI working to run .py files correctly in the browser window, using the option +ExecCGI and adding .py to the AddHandler line in the /XAMPP/apache/conf/httpd.conf.



      Normally the first two lines need to look like this with CGI in order for the .py file to run correctly:



      #!C:/Python/Python36_x86/python.exe
      print("Content-Type: text/htmln")


      However, after reading Apache2.4 documentation for ScriptInterpreterSource: https://httpd.apache.org/docs/2.4/mod/core.html#scriptinterpretersource



      I added the correct registry key mentioned in the documentation along with the line:



      ScriptInterpreterSource Registry-Strict


      to my /XAMPP/apache/conf/httpd.conf



      and was able to run my Python script without those first two lines. However, it still requires an extra print() statement on the first line (or print('n') ).



      ===========================================================================



      MY QUESTION:



      Is there any way at all to get around needing the print/newline statement on the first line of the Python script?







      windows apache-http-server python php cgi






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 12 '18 at 20:34









      Maleko48Maleko48

      64




      64






















          1 Answer
          1






          active

          oldest

          votes


















          0















          Is there any way at all to get around needing the print/newline statement on the first line of the Python script?




          Probably not... at least not for using Python via CGI.



          For a given CGI script (not just those in Python), the language-equivalent of this "blank line" (CRLF) is needed at the start of any data returned to the browser. And while Apache grabs the interpreter path and value for the Content-type header from the registry, it appears not to include this line.




          It still requires an extra print() statement on the first line (or print('n') ).




          For clarity, in case there is any confusion, it simply has to be the first line of text you output (if any) from your script e.g.:



          # Print our Python version

          import sys

          version = sys.version_info
          full_version = str(version.major) + '.' + str(version.minor) + '.' + str(version.micro)

          # 8000 more lines that don't include print()...

          # === Our first line(s) of text output ===
          # print ('Content-type: text/html')
          print ('')

          print ('Python Version: ', full_version)




          Note (for everyone else): If you don't have everything registered like OP, you still need a hash-bang such as !# python as your first line and should uncomment print ('Content-type: text/html').









          share|improve this answer


























          • Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

            – Maleko48
            Mar 13 '18 at 17:27











          • No worries. You're welcome. =)

            – Anaksunaman
            Mar 13 '18 at 17:43











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f1302813%2fxampp-apache-setup-on-windows-to-run-py-python-files-scriptinterpretersource%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









          0















          Is there any way at all to get around needing the print/newline statement on the first line of the Python script?




          Probably not... at least not for using Python via CGI.



          For a given CGI script (not just those in Python), the language-equivalent of this "blank line" (CRLF) is needed at the start of any data returned to the browser. And while Apache grabs the interpreter path and value for the Content-type header from the registry, it appears not to include this line.




          It still requires an extra print() statement on the first line (or print('n') ).




          For clarity, in case there is any confusion, it simply has to be the first line of text you output (if any) from your script e.g.:



          # Print our Python version

          import sys

          version = sys.version_info
          full_version = str(version.major) + '.' + str(version.minor) + '.' + str(version.micro)

          # 8000 more lines that don't include print()...

          # === Our first line(s) of text output ===
          # print ('Content-type: text/html')
          print ('')

          print ('Python Version: ', full_version)




          Note (for everyone else): If you don't have everything registered like OP, you still need a hash-bang such as !# python as your first line and should uncomment print ('Content-type: text/html').









          share|improve this answer


























          • Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

            – Maleko48
            Mar 13 '18 at 17:27











          • No worries. You're welcome. =)

            – Anaksunaman
            Mar 13 '18 at 17:43
















          0















          Is there any way at all to get around needing the print/newline statement on the first line of the Python script?




          Probably not... at least not for using Python via CGI.



          For a given CGI script (not just those in Python), the language-equivalent of this "blank line" (CRLF) is needed at the start of any data returned to the browser. And while Apache grabs the interpreter path and value for the Content-type header from the registry, it appears not to include this line.




          It still requires an extra print() statement on the first line (or print('n') ).




          For clarity, in case there is any confusion, it simply has to be the first line of text you output (if any) from your script e.g.:



          # Print our Python version

          import sys

          version = sys.version_info
          full_version = str(version.major) + '.' + str(version.minor) + '.' + str(version.micro)

          # 8000 more lines that don't include print()...

          # === Our first line(s) of text output ===
          # print ('Content-type: text/html')
          print ('')

          print ('Python Version: ', full_version)




          Note (for everyone else): If you don't have everything registered like OP, you still need a hash-bang such as !# python as your first line and should uncomment print ('Content-type: text/html').









          share|improve this answer


























          • Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

            – Maleko48
            Mar 13 '18 at 17:27











          • No worries. You're welcome. =)

            – Anaksunaman
            Mar 13 '18 at 17:43














          0












          0








          0








          Is there any way at all to get around needing the print/newline statement on the first line of the Python script?




          Probably not... at least not for using Python via CGI.



          For a given CGI script (not just those in Python), the language-equivalent of this "blank line" (CRLF) is needed at the start of any data returned to the browser. And while Apache grabs the interpreter path and value for the Content-type header from the registry, it appears not to include this line.




          It still requires an extra print() statement on the first line (or print('n') ).




          For clarity, in case there is any confusion, it simply has to be the first line of text you output (if any) from your script e.g.:



          # Print our Python version

          import sys

          version = sys.version_info
          full_version = str(version.major) + '.' + str(version.minor) + '.' + str(version.micro)

          # 8000 more lines that don't include print()...

          # === Our first line(s) of text output ===
          # print ('Content-type: text/html')
          print ('')

          print ('Python Version: ', full_version)




          Note (for everyone else): If you don't have everything registered like OP, you still need a hash-bang such as !# python as your first line and should uncomment print ('Content-type: text/html').









          share|improve this answer
















          Is there any way at all to get around needing the print/newline statement on the first line of the Python script?




          Probably not... at least not for using Python via CGI.



          For a given CGI script (not just those in Python), the language-equivalent of this "blank line" (CRLF) is needed at the start of any data returned to the browser. And while Apache grabs the interpreter path and value for the Content-type header from the registry, it appears not to include this line.




          It still requires an extra print() statement on the first line (or print('n') ).




          For clarity, in case there is any confusion, it simply has to be the first line of text you output (if any) from your script e.g.:



          # Print our Python version

          import sys

          version = sys.version_info
          full_version = str(version.major) + '.' + str(version.minor) + '.' + str(version.micro)

          # 8000 more lines that don't include print()...

          # === Our first line(s) of text output ===
          # print ('Content-type: text/html')
          print ('')

          print ('Python Version: ', full_version)




          Note (for everyone else): If you don't have everything registered like OP, you still need a hash-bang such as !# python as your first line and should uncomment print ('Content-type: text/html').










          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 14 at 0:29

























          answered Mar 13 '18 at 12:12









          AnaksunamanAnaksunaman

          5,56321322




          5,56321322













          • Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

            – Maleko48
            Mar 13 '18 at 17:27











          • No worries. You're welcome. =)

            – Anaksunaman
            Mar 13 '18 at 17:43



















          • Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

            – Maleko48
            Mar 13 '18 at 17:27











          • No worries. You're welcome. =)

            – Anaksunaman
            Mar 13 '18 at 17:43

















          Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

          – Maleko48
          Mar 13 '18 at 17:27





          Thank you for your answer, but I am not allowed to mark it or anything since I am a new member with <15 rep.

          – Maleko48
          Mar 13 '18 at 17:27













          No worries. You're welcome. =)

          – Anaksunaman
          Mar 13 '18 at 17:43





          No worries. You're welcome. =)

          – Anaksunaman
          Mar 13 '18 at 17:43


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1302813%2fxampp-apache-setup-on-windows-to-run-py-python-files-scriptinterpretersource%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

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix