0

I am trying to deploy my Django application with Azure DevOps as a Azure Web App. The application is pipelined and build to the web app but it will not run. When I am trying to run py manage.py runserver in the Diagnostic Console i get the error below:

D:\Python34\python.exe: can't open file 'manage.py': [Errno 0] No error

Does anyone have a clue on what the issue might be? This is the first project I am trying to deploy with Azure so my knownledge is not very good. The project files are stored on the following location on the server

D:\home\site\wwwroot\<applicationName>

I am sometimes getting this error as well:

Window title cannot be longer than 1023 characters.

Filestructure

wwwroot
--- applicationname
------ api
------ applicationname
------ .env
------ db.sqlite3 (empty and not in use)
------ manage.py
------ requirements.txt

Things that have been tried to solved the issue

  1. Changing the filepath in Configuration -> Path Mappings -> Physical Path after an idea from Jason Pan
  2. Add a web.config file (Added in wwwroot -> applicationname -> web.config). The Config file is pasted below. This resulted in the following error: The specified CGI application encountered an error and the server terminated the process.

Web.Config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>

  <handlers>
    <add name="httpPlatformHandler" path="*" verb="*"
               modules="httpPlatformHandler" resourceType="Unspecified"/>
  </handlers>

  <httpPlatform processPath="D:\home\python364x64\python.exe" arguments="manage.py runserver %HTTP_PLATFORM_PORT%" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
    <environmentVariables>
     <environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot"/>
    </environmentVariables>
  </httpPlatform>

 </system.webServer>
</configuration>

Thank you for your help.

SOLUTION
After huge help from Jason Pan i manage to set it up as a Container Service instead and the app is now working as it should! Thank you very much Jason!

1 Answers1

0

Newest

Previous we change path, we need to modify it back.

enter image description here

Step 1. Add Extensions.

enter image description here

Step 2. Add web.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="D:\home\python364x64\python.exe"
                  arguments="D:\home\site\wwwroot\manage.py runserver %HTTP_PLATFORM_PORT%"
                  stdoutLogEnabled="true"
                  stdoutLogFile="D:\home\LogFiles\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

Step 3. Make sure that the directory structure in your wwwroot folder is the same as mine.

enter image description here

Step 4. Run command pip install python-decouple in python364x64.

enter image description here

Step 5. Then your app will be ok. If also have issues, you can troubleshoot like me.

enter image description here

Test Result.

In local.

enter image description here

After deployed.

enter image description here

enter image description here


Your directory structure should look like this. And it will work fine.

wwwroot
--- api
--- applicationname
--- .env
--- db.sqlite3 (empty and not in use)
--- manage.py
--- requirements.txt

In order to verify my guess, you can test like this in the portal.

enter image description here

Then restart your web app, if it works, it also can be a solution. The reason for this problem before was that the folder applicationname was added.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Hi and thank you for your response! I followed your steps changing the file path, but the error is still the same. I have noticed that I am getting a new error aswell when trying to run the manage.py runserver command ---> Window title cannot be longer than 1023 characters. Edit: Updated the original post with this error. – Marius Bekk Apr 05 '21 at 09:20
  • @MariusBekk Try to add webconfig file which contains httpplatformhandler. – Jason Pan Apr 05 '21 at 09:33
  • I will try that, but am a little unsure on how so I will have to figure that out first. A another thing I found out is that when I try to edit the manage.py file from the diagnostic tool I can an error saying that I have no persmissions to do that... Can that be the issue or is it normal that you cannot write to the file from this view? – Marius Bekk Apr 05 '21 at 09:42
  • I added a Web.Config file, see the content in the original post. I am now getting this error: "The specified CGI application encountered an error and the server terminated the process" – Marius Bekk Apr 05 '21 at 10:08
  • @MariusBekk If possible you can upload your sample code without sensitive info,I can help you tomorrow. – Jason Pan Apr 05 '21 at 10:15
  • @MariusBekk Because I don't have specific parameters, I can only make the local results consistent with the deployed results. Please remember to delete your source code sharing. – Jason Pan Apr 06 '21 at 08:45
  • The data is not that secret as it is a dev environment with mostly dummydata.. You could get the .env file with the secrets as well if that helps? :) – Marius Bekk Apr 06 '21 at 09:06
  • @MariusBekk I'm not sure, but currently the local and azure running results are consistent. – Jason Pan Apr 06 '21 at 09:07
  • I will try to replicate what you did first and let you know. Thank you so far for this amazing help :D – Marius Bekk Apr 06 '21 at 09:08
  • @MariusBekk If you need further help, pls let me know. – Jason Pan Apr 06 '21 at 09:09
  • Python logfile: D:\home\python364x64\python.exe: can't open file 'D:\home\site\wwwroot\manage.py': [Errno 0] No error – Marius Bekk Apr 06 '21 at 11:56
  • The files are in the same place as you have them (Directly under wwwroot) - And I followed your steps to the letter. – Marius Bekk Apr 06 '21 at 11:58
  • @MariusBekk Can you check application logs on portal? – Jason Pan Apr 06 '21 at 12:03
  • @MariusBekk Make sure your web.config under wwwroot folder, and same as mine. – Jason Pan Apr 06 '21 at 12:04
  • The application log says the same thing (D:\home\python364x64\python.exe: can't open file 'D:\home\site\wwwroot\manage.py': [Errno 0] No error) – Marius Bekk Apr 06 '21 at 12:24
  • The web.config file is under wwwroot folder and the same as yours! – Marius Bekk Apr 06 '21 at 12:24
  • Can it be that for some reason it doesn't have the rights to run it? And do you know how to check this? – Marius Bekk Apr 06 '21 at 12:25
  • @MariusBekk Can you create a new sample for me with .env (no sensitive info) which I can run in my local. And when I success, I can give you more details. – Jason Pan Apr 06 '21 at 12:51
  • Just let me know when you have the repo url and I will delete again :) Thank you! – Marius Bekk Apr 06 '21 at 13:02
  • @MariusBekk Pls delete your .env file and repo, I can run in my local. https://imgur.com/a/BbC4gHb – Jason Pan Apr 07 '21 at 04:12
  • Done. A little side-note: I tried to create a new Azure Web app yesterday and push the code to that. Same error there. – Marius Bekk Apr 07 '21 at 05:16
  • @MariusBekk Your issue has been solved by yourself ? – Jason Pan Apr 07 '21 at 07:17
  • @MariusBekk I am testing. – Jason Pan Apr 07 '21 at 07:18