question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding another route causes 404 on cloud deploy only

See original GitHub issue

Originally, In main.py there is a function named hello_world

@app.route('/')
def hello_world():
    return 'Hello, World!'

I added another function below

@app.route('/hello')
def hello_path():
    return "HELLO FROM PATH"

So the full script is as follows:

from flask import Flask
app = Flask(__name__)
app.debug = True
    
@app.route('/')
def hello_world():
    return 'Hello, World!'
    
@app.route('/hello')
def hello_path():
    return "HELLO FROM PATH"
    
if __name__ == '__main__':
    app.run()

When I run this on my localhost both endpoints work correctly and return their respective strings. However, after deploying via git to my azure website, I can only get the response from xxx.azurewebsites.net/ to work correctly (returns “Hello, World!”). When I try and hit xxx.azurewebsites.net/hello I get a 404 error.

I’m not sure why it only works with the default route in the cloud when everything works fine locally. Is this a setup issue? Is there anyway I can debug the routing issues on Azure?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jtmottcommented, Sep 1, 2017

@hgirish solution worked for me as well, i.e., add the following to your web.3.4.config:

<system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="Python27_via_FastCGI" />
      <remove name="Python34_via_FastCGI" />
      <add name="Python FastCGI"
           path="handler.fcgi"
           verb="*"
           modules="FastCgiModule"
           scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py"
           resourceType="Unspecified"
           requireAccess="Script" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
1reaction
hgirishcommented, Jul 7, 2017

Adding System.Web and System.WebServer block to web.3.4.config from https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/app-service-web/web-sites-python-configure.md worked for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error 404: 4 Ways to Fix It - Hostinger
Error 404 is a response code, meaning the server could not locate the requested content. Check this article to learn 4 steps to...
Read more >
404 on any route for Flask app deployed to Elastic Beanstalk
Have you tried hosting the app on a different port (just for testing it out) and allowing through the firewall?
Read more >
Troubleshoot External HTTP(S) Load Balancing - Google Cloud
The backend unexpectedly closed its connection to the load balancer before the response was proxied to the client. This can happen if the...
Read more >
How to Fix Error 404 Not Found on Your WordPress Site - Kinsta
Users then try to access the content at the old location and see a 404 page instead of the resource they were expecting....
Read more >
404 Not Found firebasedeploy - Atlassian Community
The root cause can also be not in CLI only, but in google-cloud-functions configuration or hosting, but to investigate that in more detail,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found