locked
Error when publishing Flask app with pyodbc import RRS feed

  • Question

  • I am having a problem running Flask app when importing pyodbc. I have included pyodbc (version 3.0.10) in my requirements.txt. 

    I am trying to use pyodbc to connect to an Access database that is part of my web application.  The application works perfectly when I run it locally (in Visual Studio), but when I publish it to Azure I get this error:
    "The page cannot be displayed because an internal server error has occurred." 

    When I look at the Log strem on the Azure dashboard, I see this message:
    <fieldset><h4>Most likely causes:</h4> <ul> <li>IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.</li> <li>IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.</li> <li>IIS was not able to process configuration for the Web site or application.</li> <li>The authenticated user does not have permission to use this DLL.</li> <li>The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.</li> </ul> </fieldset>
    Thank you. 


    Wednesday, September 28, 2016 12:43 AM

Answers

  • I figured it out.

    I found a logged error:

    DLL load failed: %1 is not a valid Win32 application.

    If you are using the 64 bit version of Python on your computer it will fail on Azure, which is only 32 bit.

    Make sure that the Python environment you are using is the 32 bit version of Python.

    • Marked as answer by Swikruti Bose Sunday, June 18, 2017 1:02 PM
    Saturday, June 17, 2017 5:37 PM

All replies

  • Hello,

    Thank you for posting here!

    pyodbc does not need any dependencies. So, it should work properly. Have you tried to copy your requirements.txt and added pyodbc in it and ran env/Scripts/pip.exe install -r requirements.txt?

    Also, you can use kudu console to get more error details. Please refer this link for the same, https://blogs.msdn.microsoft.com/benjaminperkins/2014/04/01/get-azure-website-deployment-logs-from-kudu/

    https://github.com/projectkudu/kudu/wiki/Investigating-issues

    And you can use fiddler also to get more details on error.

    Regards,
    Swikruti

    If a post answers your question, please click Mark as Answer on that post and Vote as Helpful.

    Wednesday, September 28, 2016 11:04 AM
  • Hi Swikruti,

    Thanks for the tip on using Kudu.  I did try to do a pip install -r requirements.txt

    I am still getting an error:

    <div class="content-container"> 
    <fieldset><h4>Most likely causes:</h4> 
    <ul> 	<li>IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.</li> 	<li>IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.</li> 	<li>IIS was not able to process configuration for the Web site or application.</li> 	<li>The authenticated user does not have permission to use this DLL.</li> 	<li>The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.</li> </ul> 
    </fieldset> 
    </div> 
    <div class="content-container"> 
    <fieldset><h4>Things you can try:</h4> 
    <ul> 	<li>Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.</li> 	<li>Check the event logs to see if any additional information was logged.</li> 	<li>Verify the permissions for the DLL.</li> 	<li>Install the .NET Extensibility feature if the request is mapped to a managed handler.</li> 	<li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
    </fieldset> 
    </div> 
    <fieldset><h4>Detailed Error Information:</h4> 
    <div id="details-left"> 
    <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;FastCgiModule</td></tr> 
    <tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;ExecuteRequestHandler</td></tr> 
    <tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;Python FastCGI</td></tr> 
    <tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x00000000</td></tr> 
    I get this error message towards the bottom of my logstream:
    System.ApplicationException: The trace listener AzureBlobTraceListener is disabled. ---> System.InvalidOperationException: The SAS URL for the cloud storage account is not specified. Use the environment variable 'DIAGNOSTICS_AZUREBLOBCONTAINERSASURL' to define it.
       at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.RefreshConfig()
    Note that if I comment out the import pyodbc, the application works, but gives me the error when I include the import. 

    Any additional thoughts on this? 

    Wednesday, September 28, 2016 5:56 PM
  • Hello,

    Apologize for delay in response.

    I would suggest you, try this document: https://cricstor.wordpress.com/2016/02/18/flask-with-ms-sql-server-or-azure-sql/ which might help you.
    Also, you can try to connect pyodbc using FreeTDS, might help you

    import pyodbc
    
    pyodbc.connect('DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;')

    Regards,
    Swikruti

    If a post answers your question, please click Mark as Answer on that post and Vote as Helpful.

    Monday, November 7, 2016 2:09 PM
  • Hi,

    I'm running into the same problem. Did you ever figure out how to fix it?

    Thursday, December 29, 2016 5:59 PM
  • I'm having the same problem.

    Note that it happens when

    import pyodbc

    is called - it is not necessary to call

    pyodbc.connect(...)
    I have pyodbc is my requirements.txt file, and it works correctly in the virtual environment on my desktop.

    Saturday, June 17, 2017 5:21 AM
  • I figured it out.

    I found a logged error:

    DLL load failed: %1 is not a valid Win32 application.

    If you are using the 64 bit version of Python on your computer it will fail on Azure, which is only 32 bit.

    Make sure that the Python environment you are using is the 32 bit version of Python.

    • Marked as answer by Swikruti Bose Sunday, June 18, 2017 1:02 PM
    Saturday, June 17, 2017 5:37 PM
  • Glad to know that your issue has been resolved.
    Sunday, June 18, 2017 1:02 PM