[英]504- Gateway timeout only in django function
I have a very mind-boggling problem and my team has struggled to solve it.我有一个非常令人难以置信的问题,我的团队一直在努力解决它。 We do have it narrowed down but not 100%.
我们确实缩小了范围,但不是 100%。
We are trying to implement LTI in a Django app with the Vue frontend.我们正在尝试使用 Vue 前端在 Django 应用程序中实现 LTI。 To fetch the token from the URL the backend makes a
POST
request to the URL with data and should receive a token or error if it's expired or invalid.为了从 URL 中获取令牌,后端向 URL 发出带有数据的
POST
请求,如果令牌过期或无效,则应该收到令牌或错误。
Browser ---- POST REQUEST --> view function on Server (Django)
--- POST REQUEST --> Auth URL
浏览器 ---- POST REQUEST -->
Server (Django)
--- POST REQUEST --> Auth URL
The post request that Django view makes times out with 504 Gateway Timeout
. Django 查看的 post 请求以
504 Gateway Timeout
。 This could be normal if the server takes a lot of time.如果服务器花费大量时间,这可能是正常的。 However, increasing the time did not help and checked Auth URL with POSTMAN it worked fine and was not down.
但是,增加时间并没有帮助,并使用 POSTMAN 检查了 Auth URL,它工作正常并且没有关闭。
What I have tried我试过的
We decided to debug or diagnose this issue that why a code block works in a function when it is called through a shell but not when it is called by a POST
request does not.我们决定调试或诊断这个问题,即为什么代码块在通过 shell 调用时在函数中起作用,但在被
POST
请求调用时却不起作用。
POSTMAN
to send a POST
request to my Django server -- timeout on the Auth URLPOSTMAN
向我的 Django 服务器发送POST
请求——Auth URL 超时Django
shell
-- workedDjango
shell
调用相同的函数——工作What it appears to be它看起来是什么
When a POST function is called and another post request is made inside it then it times out.当调用 POST 函数并在其中发出另一个 post 请求时,它会超时。 Please note: If I make a
POST
request in the same situation with invalid data (say missing grant_type
) then it does not time out.请注意:如果我在相同情况下使用无效数据(比如缺少
grant_type
)发出POST
请求,那么它不会超时。
Code Block代码块
auth_request = {
"grant_type": "client_credentials",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJVbzNJWWlSR0ZDYUhNNEg0S2lid095enAtRU9KWlAweXkwd0g3bk5VOEEifQ.eyJpc3MiOiI2NjkxNmZmYy03YjE5LTQ0MWEtYjE5Zi0yOGQxMzVmYjZjOWYiLCJzdWIiOiI2NjkxNmZmYy03YjE5LTQ0MWEtYjE5Zi0yOGQxMzVmYjZjOWYiLCJhdWQiOiJodHRwczovL2RldmVsb3Blci5ibGFja2JvYXJkLmNvbS9hcGkvdjEvZ2F0ZXdheS9vYXV0aDIvand0dG9rZW4iLCJpYXQiOjE2NTMyODcyNzMsImV4cCI6MTY1MzI4NzMzOCwianRpIjoibHRpLXNlcnZpY2UtdG9rZW4tMDQyZTZhNjctNDA2My00YmQ1LWI2NmQtNTM4YjU2ZTllM2Q1In0.8Jaou965cPTCFv-7yP9iIlH8mMgQjAi0AR2li0KwCcRuHsRZ_1OpbE83bZ06RMXhbjA4crRqTI4zMi8aNfq16Mkg4lXoPj8JiJW7q8b_ZQ1rLZvIojmabehYjpyscHRitFPLibfTYF2mCjUyHqwPgnFRLNrHIVuSvM0BiK56PuYK6SiiSjxu2U3bmJqOHNW2mqx2YYfkaXx2u7ru6CKTiL3KBGzFPYjCUwwWNBdbz4R0g0aHK_l-hhA3oi_pCDZOyqdnyCmGAj5SpZbuZOqrZbQBrqPoEFtXdNDPpHGGwW7IUbbmCtsmE2NqQiYt6snmK-1pbxsLxE0mXrpDqASh4A",
"scope": "https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly",
}
response = requests.post(
"https://developer.blackboard.com/api/v1/gateway/oauth2/jwttoken",
data=auth_request,
)
response = response.json()
print(response)
After days of trying to figure it out, we deployed the project with Production
settings and it worked.经过几天的尝试,我们使用
Production
设置部署了该项目,并且成功了。 Upon investigation on why it was not working on staging we found the following:在调查了它为什么不能进行分期工作后,我们发现了以下内容:
jwks
message it sent another request to a URL on our staging server.jwks
消息,所以它向我们登台服务器上的 URL 发送了另一个请求。gunicorn
did the trickgunicorn
添加线程参数就可以了gunicorn ripple.wsgi --reload --log-level debug --threads 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.