将 Requests 库与 WSGI 一起使用
Using Requests library with WSGI
我正在创建一个 GroupMe 机器人,它托管在 Heroku 上,使用 Gunicorn 作为 WSGI 服务器。
当我尝试部署应用程序时,我得到一个 failed to find object 'app' in 'MODULE_NAME' error
,我想是因为我没有可调用的 WSGI。
这是我的:
def app():
while True:
rqResponse = requests.get('https://api.groupme.com/v3/groups/' + groupID +'/messages', params = requestParams)
# Pings the gm-membot Heroku app so it doesn't idle.
requests.get('http://gm-bot.herokuapp.com')
if rqResponse.status_code == 200:
gotten = rqResponse.json()['response']['messages']
for message in gotten:
messageText = message['text'].lower()
if (messageText in bot_reply.staticTriggers) or (messageText in bot_reply.dynamicTriggers):
bot_reply.botReply(message)
requestParams['since_id'] = message['id']
else:
raise Exception('error')
break
time.sleep(5)
我的 Procfile 输出:
web: gunicorn MODULE_NAME:app --workers=1
但是,在查看了 Gunicorn 和 WSGI 的文档之后,我不知道如何将它与我已经使用 Requests 库编写的代码相结合。有什么方法可以让 Gunicorn 在不进行大量重写的情况下工作吗?另外,我对此很陌生,所以如果有明显的答案,我深表歉意。
(P.S。如果我将应用程序托管在我的笔记本电脑上,一切正常!)
我找到了两个答案: and ,但我认为这是服务器上的内存泄漏(因为您说本地托管一切正常)。
试试让我知道
我正在创建一个 GroupMe 机器人,它托管在 Heroku 上,使用 Gunicorn 作为 WSGI 服务器。
当我尝试部署应用程序时,我得到一个 failed to find object 'app' in 'MODULE_NAME' error
,我想是因为我没有可调用的 WSGI。
这是我的:
def app():
while True:
rqResponse = requests.get('https://api.groupme.com/v3/groups/' + groupID +'/messages', params = requestParams)
# Pings the gm-membot Heroku app so it doesn't idle.
requests.get('http://gm-bot.herokuapp.com')
if rqResponse.status_code == 200:
gotten = rqResponse.json()['response']['messages']
for message in gotten:
messageText = message['text'].lower()
if (messageText in bot_reply.staticTriggers) or (messageText in bot_reply.dynamicTriggers):
bot_reply.botReply(message)
requestParams['since_id'] = message['id']
else:
raise Exception('error')
break
time.sleep(5)
我的 Procfile 输出:
web: gunicorn MODULE_NAME:app --workers=1
但是,在查看了 Gunicorn 和 WSGI 的文档之后,我不知道如何将它与我已经使用 Requests 库编写的代码相结合。有什么方法可以让 Gunicorn 在不进行大量重写的情况下工作吗?另外,我对此很陌生,所以如果有明显的答案,我深表歉意。
(P.S。如果我将应用程序托管在我的笔记本电脑上,一切正常!)
我找到了两个答案:
试试让我知道