如何修复500 Internal Server Error / web.py

时间:2019-08-15 19:47:43

标签: python pymongo web.py

我收到此错误,很不幸,我尝试使用web.py创建一个简单的Web项目,当我尝试注册用户时遇到了错误,并且我已经尝试过更改属性,但无法解决问题< / p>

Date

我已经检查了文件(Main.py,RegistrationModel.py和Register.HTML),但没有找到错误。

File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\utils.py", line 75, in   __getattr__
    return self[key]
KeyError: 'name'

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\application.py", line 257, in process
    return self.handle()
  File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\application.py", line 248, in handle
    return self._delegate(fn, self.fvars, args)
  File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\application.py", line 488, in _delegate
    return handle_class(cls)
  File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\application.py", line 466, in handle_class
    return tocall(*args)
  File "controller.py", line 57, in POST
    reg_model.insert_user(data)
  File "C:\Users\Pippo\Desktop\UDEMY\The Complete Python 3 Course - Beginner to Advanced\Web development project Using web.py\CodeWizzard\Models\RegisterModel.py", line 15, in insert_user
    id = self.Users.insert({"username": data.username, "name": data.name, "password": hashed,
  File "C:\Users\Pippo\Anaconda3\lib\site-packages\web\utils.py", line 77, in __getattr__
    raise AttributeError(k)
AttributeError: 'name'


127.0.0.1:55572 - - [15/Aug/2019 20:54:31] "HTTP/1.1 POST /postregistration" - 500 Internal Server Error

任何想法为何会出现此错误?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您似乎没有在POST请求的有效载荷中传递name

您可以使用forms模块来验证输入。

http://webpy.org/cookbook/forms

或者如果web.input是可选输入,则将默认值指定为name

data = web.input(name="default-name")