当前位置: 首页 > 面试题库 >

Azure Flask HTTP错误500.0-内部服务器错误

商皓
2023-03-14
问题内容

我在Microsoft Azure上托管了一个简单的Flask Web应用程序,该应用程序允许用户登录,上传文件,查看上传的文件并注销。
现在,为了更有效地处理用户,我决定使用flask的会话。
这是我的示例代码

'''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')

每当我尝试添加 session [‘username’] = username时 ,应用都会崩溃,并显示内部服务器错误。

由于我是Azure新手,我不确定要发布什么日志文件。这是事件日志

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>

这是堆栈跟踪

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 ---

这是详细错误

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

问题答案:

使用会话变量之前,您是否已设置app.secret_key?我有同样的问题,它在本地工作,但是天蓝色抛出“内部服务器错误”,因为我在_name__
==’_main__’块中设置了它,如下所示:

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)

我在if块之外设置了app.secret_key =“ secret_key”,它可以正常工作。



 类似资料:
  • 我是新的角度6。我用spring boot开发了一个post服务,当我通过postman测试它时,它工作得很好,但当我用web浏览器测试它时,它给了我这个错误: HttpErrorResponse ;{headers:HttpHeaders,status:500,statusText:“ok”,URL:“http://localhost:8080/api/test/ordermiss”,ok:fa

  • 我用wordpress和woocommerce(www.jescesole.eu)建立了一个网站。由于该网站在德国销售,我不得不在最近几天安装一个附加插件,woocommerce germanized(与polylang一起,以德语和意大利语查看内容),我升级了wp和所有插件,但当客户提交订单时,会出现一条内部服务器错误消息。我阅读了服务器错误日志,并报告了一条很长的错误消息: 周四,13四月20

  • 问题内容: 我正在尝试为这个工作中的项目学习AJAX。我有一个网站加载病人正在服用的药物。 我递归调用此AJAX函数,以便它将附加一个包含单种药物和7天历史记录的新表。我在使代码在FF和IE中执行时遇到问题。在chrome中效果很好。我有显示xmlhttp.status的警报,这是我得到的: xmlhttp.status == 500(内部服务器错误)。 我注释掉了所有递归,因此将其范围缩小到了这

  • 我收到以下错误 内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 请联系服务器管理员,webmaster@strivemedicare.in并告知他们错误发生的时间,以及可能导致错误的任何行为。 有关此错误的详细信息,请参阅服务器错误日志。 此外,尝试使用错误文档处理请求时遇到 500 内部服务器错误错误。

  • 我的laravel项目通过Commission在localhost中运行良好。现在我正试图在web主机上托管它。我在下上传我的项目,并从文件夹复制所有文件,我也编辑

  • 问题内容: 大家好,我在laravel和ajax中使用我的评论系统时遇到问题。实际上,它仅适用于php,但我遇到了ajax问题。 这是错误消息: 状态码:500内部服务器错误。并且错误显示:1/3 SQLSTATE [23000]:违反完整性约束:1048列’post_id’不能为null。 我正在编辑模态中的注释,我可以创建一个新注释,但是问题是使用ajax编辑它。 JS代码: 这是HTML: