1
votes

I'm experiencing strange behaviour from msbuild when running a deployment. When calling it from within a Python script via subprocess.Popen(), the call fails with ERROR_USER_UNAUTHORIZED. However, I print to console the exact command fired. If I copy & paste the exact commant into a windows console, the msbuild command works perfectly. What's wrong with the call from within Python (note: setting Shell=False doesn't change anything in this case). This is for the msbuild that comes w/ VisualStudio 2013.

Here's the Python code:

    # Execute. "action" is list of strings.
    def execute(self, action):
        # Execute the subprocess and connect stdout pipe.
        # Redirect stderr to also stream to stdout
        p = subprocess.Popen(action, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)

        # Continuously read process output and write to log window
        lines_iterator = iter(p.stdout.readline, b'')

        # Fetch lines from pipe while child is running
        while p.poll() is None:
            for line in lines_iterator:
                self.add_log(line.decode('cp850'))

        # Returncode will be 0 if everything went fine. Note that a build error
        # results in a nonzero result code always (no exception)
        if p.returncode != 0:
            raise Exception("Command returned nonzero exit code")

Here's the (anonymized) command sent to msbuild:

msbuild.exe
  myproj.csproj
  /P:Platform=AnyCPU
  /P:UserName=publish
  /P:Password=****
  /P:DeployOnBuild=True
  /P:DeployTarget=MSDeployPublish
  /P:AllowUntrustedCertificate=True
  /P:MSDeployPublishMethod=WMSvc
  /P:CreatePackageOnPublish=True
  /v:quiet
  /P:MsDeployServiceUrl=<my url>/MsDeploy.axd
  /P:DeployIisAppPath="my_app_path"
  /P:Configuration=Release

Here's the exact error message (German, unfortunately):

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4255,5): msdeploy error ERROR_USER_UNAUTHORIZED: Web deployment task failed. (Die Verbindung mit dem Remotecomputer ("") wurde mit dem Webverwaltungsdienst hergestellt, eine Autorisierung war jedoch nicht möglich. Stellen Sie sicher, dass Sie den korrekten Benutzernamen und das korrekte Kennwort verwenden, dass die Website, mit der eine Verbindung hergestellt werden soll, vorhanden ist und dass die Anmeldeinformationen einen Benutzer darstellen, der für den Zugriff auf die Website berechtigt ist.

In English, it basically says that it could reach the server, but couldn't authorize.

1
Note: Before calling this, I rebuild the solution, also via the execute() method shown above. This works perfectly from within Pyhton, only the deployment fails. It also fails if I run the Python script as administrator. - Flo

1 Answers

0
votes

Meanwhile, I have a workaround for this. The python script writes to complete command (thus: " ".join(arglist)) into a batchfile and executes the batchfile (with Shell=True). This works. Still no idea why the direct deployment call fails always.