How to run django management custom commands with escalated privileges?










0















I am trying to run a custom django management command from my views. I have the view ready to execute the command as shown below:



from django.core.management import call_command
import django

def send_queued_mails():
# Run Django Setup
django.setup()
call_command('send_all_queued_mails')


But, when the command is executed on my windows machine, I get the following error:



 os.symlink(self.pid_filename, self.lock_filename)
OSError: symbolic link privilege not held


I can tackle this manually by running the terminal as Administrator but I want to run the command through my views and with escalated privileges.



Any ideas or suggestions are appreciated.



PS: I also tried using OS level command as shown below:



from subprocess import call
call(["python", "manage.py", "send_all_queued_mails"])


But I am getting the same error as above.










share|improve this question


























    0















    I am trying to run a custom django management command from my views. I have the view ready to execute the command as shown below:



    from django.core.management import call_command
    import django

    def send_queued_mails():
    # Run Django Setup
    django.setup()
    call_command('send_all_queued_mails')


    But, when the command is executed on my windows machine, I get the following error:



     os.symlink(self.pid_filename, self.lock_filename)
    OSError: symbolic link privilege not held


    I can tackle this manually by running the terminal as Administrator but I want to run the command through my views and with escalated privileges.



    Any ideas or suggestions are appreciated.



    PS: I also tried using OS level command as shown below:



    from subprocess import call
    call(["python", "manage.py", "send_all_queued_mails"])


    But I am getting the same error as above.










    share|improve this question
























      0












      0








      0








      I am trying to run a custom django management command from my views. I have the view ready to execute the command as shown below:



      from django.core.management import call_command
      import django

      def send_queued_mails():
      # Run Django Setup
      django.setup()
      call_command('send_all_queued_mails')


      But, when the command is executed on my windows machine, I get the following error:



       os.symlink(self.pid_filename, self.lock_filename)
      OSError: symbolic link privilege not held


      I can tackle this manually by running the terminal as Administrator but I want to run the command through my views and with escalated privileges.



      Any ideas or suggestions are appreciated.



      PS: I also tried using OS level command as shown below:



      from subprocess import call
      call(["python", "manage.py", "send_all_queued_mails"])


      But I am getting the same error as above.










      share|improve this question














      I am trying to run a custom django management command from my views. I have the view ready to execute the command as shown below:



      from django.core.management import call_command
      import django

      def send_queued_mails():
      # Run Django Setup
      django.setup()
      call_command('send_all_queued_mails')


      But, when the command is executed on my windows machine, I get the following error:



       os.symlink(self.pid_filename, self.lock_filename)
      OSError: symbolic link privilege not held


      I can tackle this manually by running the terminal as Administrator but I want to run the command through my views and with escalated privileges.



      Any ideas or suggestions are appreciated.



      PS: I also tried using OS level command as shown below:



      from subprocess import call
      call(["python", "manage.py", "send_all_queued_mails"])


      But I am getting the same error as above.







      django window elevated-privileges django-management-command






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 5:56









      Dhwanil shahDhwanil shah

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I found a solution which works well for me and might work for others as well. I am using django-post_office for sending emails. I traced back to the line where the error originated, it was as follows:



           if hasattr(os, 'symlink'):
          os.symlink(self.pid_filename, self.lock_filename)
          else:
          # Windows platforms doesn't support symlinks, at least not through the os API
          self.lock_filename = self.pid_filename


          The comments clearly stated that Windows does not support symlink, so, I modified the code a bit to avoid the error.



           if hasattr(os, 'symlink') and platform.system() != 'Windows':
          os.symlink(self.pid_filename, self.lock_filename)
          else:
          # Windows platforms doesn't support symlinks, at least not through the os API
          self.lock_filename = self.pid_filename


          This is not the exact solution as it does not solve the problem of escalated privileges while running that command. But, if you are facing a similar error, you can directly assign the file you want to create the symlink for to the desired file.



          If anyone knows a better way please do answer.






          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%2f53313272%2fhow-to-run-django-management-custom-commands-with-escalated-privileges%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














            I found a solution which works well for me and might work for others as well. I am using django-post_office for sending emails. I traced back to the line where the error originated, it was as follows:



             if hasattr(os, 'symlink'):
            os.symlink(self.pid_filename, self.lock_filename)
            else:
            # Windows platforms doesn't support symlinks, at least not through the os API
            self.lock_filename = self.pid_filename


            The comments clearly stated that Windows does not support symlink, so, I modified the code a bit to avoid the error.



             if hasattr(os, 'symlink') and platform.system() != 'Windows':
            os.symlink(self.pid_filename, self.lock_filename)
            else:
            # Windows platforms doesn't support symlinks, at least not through the os API
            self.lock_filename = self.pid_filename


            This is not the exact solution as it does not solve the problem of escalated privileges while running that command. But, if you are facing a similar error, you can directly assign the file you want to create the symlink for to the desired file.



            If anyone knows a better way please do answer.






            share|improve this answer



























              0














              I found a solution which works well for me and might work for others as well. I am using django-post_office for sending emails. I traced back to the line where the error originated, it was as follows:



               if hasattr(os, 'symlink'):
              os.symlink(self.pid_filename, self.lock_filename)
              else:
              # Windows platforms doesn't support symlinks, at least not through the os API
              self.lock_filename = self.pid_filename


              The comments clearly stated that Windows does not support symlink, so, I modified the code a bit to avoid the error.



               if hasattr(os, 'symlink') and platform.system() != 'Windows':
              os.symlink(self.pid_filename, self.lock_filename)
              else:
              # Windows platforms doesn't support symlinks, at least not through the os API
              self.lock_filename = self.pid_filename


              This is not the exact solution as it does not solve the problem of escalated privileges while running that command. But, if you are facing a similar error, you can directly assign the file you want to create the symlink for to the desired file.



              If anyone knows a better way please do answer.






              share|improve this answer

























                0












                0








                0







                I found a solution which works well for me and might work for others as well. I am using django-post_office for sending emails. I traced back to the line where the error originated, it was as follows:



                 if hasattr(os, 'symlink'):
                os.symlink(self.pid_filename, self.lock_filename)
                else:
                # Windows platforms doesn't support symlinks, at least not through the os API
                self.lock_filename = self.pid_filename


                The comments clearly stated that Windows does not support symlink, so, I modified the code a bit to avoid the error.



                 if hasattr(os, 'symlink') and platform.system() != 'Windows':
                os.symlink(self.pid_filename, self.lock_filename)
                else:
                # Windows platforms doesn't support symlinks, at least not through the os API
                self.lock_filename = self.pid_filename


                This is not the exact solution as it does not solve the problem of escalated privileges while running that command. But, if you are facing a similar error, you can directly assign the file you want to create the symlink for to the desired file.



                If anyone knows a better way please do answer.






                share|improve this answer













                I found a solution which works well for me and might work for others as well. I am using django-post_office for sending emails. I traced back to the line where the error originated, it was as follows:



                 if hasattr(os, 'symlink'):
                os.symlink(self.pid_filename, self.lock_filename)
                else:
                # Windows platforms doesn't support symlinks, at least not through the os API
                self.lock_filename = self.pid_filename


                The comments clearly stated that Windows does not support symlink, so, I modified the code a bit to avoid the error.



                 if hasattr(os, 'symlink') and platform.system() != 'Windows':
                os.symlink(self.pid_filename, self.lock_filename)
                else:
                # Windows platforms doesn't support symlinks, at least not through the os API
                self.lock_filename = self.pid_filename


                This is not the exact solution as it does not solve the problem of escalated privileges while running that command. But, if you are facing a similar error, you can directly assign the file you want to create the symlink for to the desired file.



                If anyone knows a better way please do answer.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 6:38









                Dhwanil shahDhwanil shah

                83




                83





























                    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%2f53313272%2fhow-to-run-django-management-custom-commands-with-escalated-privileges%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







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto