Azure Flask HTTP错误500.0 - 内部服务器错误 [英] Azure Flask HTTP Error 500.0 - INTERNAL SERVER ERROR
问题描述
-
现在为了更有效地处理用户,我决定使用瓶子中的会话。
这里是我的示例代码
$ $ p $ $ $ $ $''' b $ b from flask import render_template,request,session $ b $'''more import statements'''
@ app.route('/')
def home()
return render_template('login.html')
@ app.route('/ login_user',methods = ['GET','POST'])
def login_user ):
username = str(request.form ['username'])
password = request.form ['password']
connection = MongoClient('mongodb:// username:password @ xyz.com:pot_number/db_name')
collection = connection.db_name.demo
$ b $ record = collection.find_one({'username':username})
if password == record ['password']:
session ['username'] = username
return render_template('index.html')
else:
login_message =用户名/密码无效
返回render_template('login.html',login_mes sage = login_message)
@ app.route('/ upload',methods = ['GET','POST'])
def upload():$ b $ if'username 'in session:
return render_template('upload.html')
else:
return render_template('login.html')
@ app.route(' / logout',methods = ['GET','POST'])
def logout():
session.pop('username',None)
return render_template('login.html ')
$ p $ b每当我尝试添加 session [用户名'] =用户名的应用程序崩溃给内部服务器错误。
我不知道自从我是Azure新手之后要发布什么日志文件。
这是事件日志应用程序ID:/ LM / W3SVC / 1909144379 / ROOT
$ b
$ b进程ID:69820
例外:System.Configuration.ConfigurationErrorsException
消息:无法找到类Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,Microsoft.WindowsAzure的类型。 Diagnostics,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。
System.Diagnostics.TraceUtils.GetRuntimeObject(String类型,类型baseType,字符串initializeData)上的
$ System.Diagnostics.TypedElement.BaseGetRuntimeObject()
System.Diagnostics System.Diagnostics.TraceInternal.get_Listeners()中的
System.Diagnostics.TraceInternal.WriteLine中的
(String message)System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.Debug.WriteLine(String message)
at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(Object stateInfo)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object状态)
在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔preserveSyncCtx)$ b $在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,博olean preserveSyncCtx)System.Threading.TimerQueueTimer.CallCallback()
System.Threading.TimerQueueTimer.Fire()的
System.Threading.TimerQueue.FireNextTimers()的
System.Threading.TimerQueue.AppDomainTimerCallback()< /Data>< / EventData>< / Event>< Event>< System>< Provider Name =。NET Runtime/>< EventID> 1026< ; / EventID>< Level> 0< / Level>< Task> 0< /任务><关键字>关键字< /关键字>< TimeCreated SystemTime =2016-07-05T10:03:46Z < EventRecordID>< Channel> Application< / Channel>< Computer> RD00155DFA5791< / Computer>< Security />< / System>< EventData>< Data> Application:w3wp。 exe
Framework版本:v4.0.30319
说明:由于未处理的异常而终止进程。
异常信息:System.Configuration.ConfigurationErrorsException $ b $在System.Diagnostics.TraceUtils.GetRuntimeObject(System.String,System.Type,System.String)
在System.Diagnostics.TypedElement.BaseGetRuntimeObject )System.Diagnostics.ListenerElement.GetRuntimeObject()上的
在System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()上的
System.Diagnostics.TraceInternal.get_Listeners()上的
在System上的
。 Diagnostics.TraceInternal.WriteLine(System.String)$ b $在System.Diagnostics.Debug.WriteLine(System.String)
在Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(System.Object)$ b $ System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)$ b $ System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)
在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Thread在System.Threading.TimerQueueTimer.CireCallback()
System.Threading.TimerQueueTimer.Fire()
在System.Threading.TimerQueue.FireNextTimers ()
在System.Threading.TimerQueue.AppDomainTimerCallback()
< / Data>< / EventData>< / Event>< / Events>
这里是堆栈跟踪
2016-07-05T09:48:45
System.ApplicationException:跟踪侦听器AzureBlobTraceListener已禁用。 ---> System.InvalidOperationException:未指定云存储帐户的SAS URL。使用环境变量DIAGNOSTICS_AZUREBLOBCONTAINERSASURL来定义它。在Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.RefreshConfig()
---内部异常堆栈跟踪结束---
以下是详细错误:
详细错误信息:
模块FastCgiModule
Notification ExecuteRequestHandler
Handler Python FastCGI
错误代码0x00000000
请求的URL http:// SuperFlask:80 / handler.fcgi / login_user
物理路径D:\home\ site \wwwroot\handler.fcgi\login_user
登录方法匿名
登录用户匿名
在使用会话变量之前是否设置了app.secret_key?我有同样的问题,它在本地工作,但在Azure抛出内部服务器错误,因为我把它设置在if _name__ =='_main__'块像这样:
if __name__ =='__main__':
HOST = environ.get('SERVER_HOST','localhost')
try:
PORT = int .get('SERVER_PORT','5555'))
ValueError:
PORT = 5555
app.secret_key =secret_key
app.run(HOST,port = PORT )
我在if块外面设置了app.secret_key =secret_key p>
I have a simple flask web app hosted on Microsoft Azure which allows users to login, upload files, view uploaded files and logout.
Now to handle users more efficiently I decided to use session from flask.
here is my sample code
'''import statements'''
from flask import render_template, request, session
'''more import statements'''
@app.route('/')
def home():
return render_template('login.html')
@app.route('/login_user', methods=['GET', 'POST'])
def login_user():
username = str(request.form['username'])
password = request.form['password']
connection = MongoClient('mongodb://username:password@xyz.com:pot_number/db_name')
collection = connection.db_name.demo
record = collection.find_one({'username':username})
if password == record['password']:
session['username'] = username
return render_template('index.html')
else:
login_message = "Invalid Username/Password"
return render_template('login.html',login_message=login_message)
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if 'username' in session:
return render_template('upload.html')
else:
return render_template('login.html')
@app.route('/logout', methods=['GET', 'POST'])
def logout():
session.pop('username',None)
return render_template('login.html')
whenever i try to add session['username'] = username the app crashes giving a Internal server error.
Im not sure what log file to post since I am new to Azure. Here is the event log
Application ID: /LM/W3SVC/1909144379/ROOT
Process ID: 69820
Exception: System.Configuration.ConfigurationErrorsException
Message: Couldn't find type for class Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
StackTrace: at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData)
at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.TraceInternal.get_Listeners()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Debug.WriteLine(String message)
at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(Object stateInfo)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()</Data></EventData></Event><Event><System><Provider Name=".NET Runtime"/><EventID>1026</EventID><Level>0</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2016-07-05T10:03:46Z"/><EventRecordID>348982031</EventRecordID><Channel>Application</Channel><Computer>RD00155DFA5791</Computer><Security/></System><EventData><Data>Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException
at System.Diagnostics.TraceUtils.GetRuntimeObject(System.String, System.Type, System.String)
at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.TraceInternal.get_Listeners()
at System.Diagnostics.TraceInternal.WriteLine(System.String)
at System.Diagnostics.Debug.WriteLine(System.String)
at Microsoft.Web.Compilation.Snapshots.SnapshotHelper.TakeSnapshotTimerCallback(System.Object)
at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
</Data></EventData></Event></Events>
here is the stack trace
2016-07-05T09:48:45
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()
--- End of inner exception stack trace ---
Here is the Detailed error
Detailed Error Information:
Module FastCgiModule
Notification ExecuteRequestHandler
Handler Python FastCGI
Error Code 0x00000000
Requested URL http://SuperFlask:80/handler.fcgi/login_user
Physical Path D:\home\site\wwwroot\handler.fcgi\login_user
Logon Method Anonymous
Logon User Anonymous
Have you set app.secret_key before using session variable? I had same issue, it worked locally, but threw 'Internal Server Error' in azure, because I set it in if _name__ == '_main__' block like this:
if __name__ == '__main__':
HOST = environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.secret_key = "secret_key"
app.run(HOST, port=PORT)
I set app.secret_key = "secret_key" outside of the if block and it worked.
这篇关于Azure Flask HTTP错误500.0 - 内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!