【问题标题】:Modifying the Request parameters throws Internal Server Error修改请求参数引发内部服务器错误
【发布时间】:2015-04-20 18:08:08
【问题描述】:

当使用 Python Eve 数据库挂钩时,我试图在 post call 上修改请求参数,但出现以下错误

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>
Internal Server Error
</h1>
<p>The server encountered an internal error and was unable to complete your     
request.Either the server is overloaded or there is an error in the     
application.
</p>

当我删除代码片段以修改请求参数时,资源创建成功。

请找到代码 sn-p 为:-

__author__ = 'sappal'

from eve import Eve
import time

def insert_people(items):
  # retrieve request parameter, if present
  print items['userid']
  print items['email']
  items['userid']= "Tushar_Sappal" + str(int(time.time()))
  items['email'] = "sappal.tushar"+str(int(time.time()))+"@gmail.com"
  print items

# Creating the instance of the EVE Application
app = Eve()

app.on_insert_people += insert_people

if __name__== '__main__':
  app.run(host='0.0.0.0')

【问题讨论】:

    标签: rest python-2.7 eve


    【解决方案1】:

    items 是一个列表,因此您应该像这样更新您的代码:

    def insert_people(items):
        for item in items:
            item['userid']= "Tushar_Sappal" + str(int(time.time()))
            item['email'] = "sappal.tushar"+str(int(time.time()))+"@gmail.com"
    

    在开发过程中,您通常希望在调试模式下运行您的应用程序,这样您就可以获得完整的堆栈跟踪信息:

    app.run(debug=True)
    

    只要确保在生产中运行时禁用调试模式即可。

    【讨论】:

    • @tushar_sappal 如果它为您提供了有效的解决方案,请接受并最终支持答案:)
    • 抱歉,我正忙于实施您的解决方案。我一定会投票赞成 .. :) :)
    猜你喜欢
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2019-01-08
    相关资源
    最近更新 更多