postman的使用过程中遇到的问题

Flask 关于request的一些方法或属性的整理,就参考
https://www.cnblogs.com/yy-cola/p/8066020.html
看了这个博客解决了自己第二个问题。

问题1:


400 Bad Request

Bad Request

The CSRF token is missing.

用postman进行接口测试的时候,csrf防护要关掉,等到真正在网页上测试的时候再打开

问题2:

req_dict = request.get_json()
    print(req_dict)
    username = req_dict.get("username")
    email = req_dict.get("email")
    country = req_dict.get("country")
    password = req_dict.get("password")

运行结果:

 INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    None
    INFO:werkzeug:127.0.0.1 - - [24/Dec/2018 09:02:42] "POST /api/v1.0/users HTTP/1.1" 500 -
    Traceback (most recent call last):
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 2309, in __call__
        return self.wsgi_app(environ, start_response)
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 2295, in wsgi_app
        response = self.handle_exception(e)
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 1741, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\_compat.py", line 35, in reraise
        raise value
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 2292, in wsgi_app
        response = self.full_dispatch_request()
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\_compat.py", line 35, in reraise
        raise value
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
        rv = self.dispatch_request()
      File "C:\Users\windows7\Envs\dongfener\lib\site-packages\flask\app.py", line 1799, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "C:\Users\windows7\Desktop\DongFener-demoDongFener\dfadmin\1221\dongfener\api_1_0\passport.py", line 19, in register
        username = req_dict.get("username")
    AttributeError: 'NoneType' object has no attribute 'get'

原因是postman请求时请求方式出错:
请求方式应该是json格式,参数写在raw里面,,之前出错是忘记更改格式还有参数位置写错了,写的到了form-data里面postman的使用过程中遇到的问题_第1张图片

你可能感兴趣的:(postman遇到的问题)