Git Product home page Git Product logo

allen7d / mini-shop-server Goto Github PK

View Code? Open in Web Editor NEW
709.0 29.0 202.0 8.65 MB

基于 Flask 框架开发的微信小程序后端项目,用于构建小程序商城后台 (电商相关;rbac权限管理;附带自动生成Swagger 风格的API 文档;可作「Python 项目毕设」)---- 相关博客链接:🌟

License: MIT License

Python 99.14% CSS 0.15% HTML 0.71%
flask mini-shop python sqlalchemy swagger restful-api rbac mysql

mini-shop-server's Introduction

mini-shop-server

构建微信小程序(商城)后端
🤜基于 Flask 框架🤛

  • 本项目的开发环境是 Mac OS,生产环境是 Linux Ubuntu 16.04
  • 感谢慕课网的七月老师,本项目初期是基于他的课程思路

🎮 互动

QQ交流群:聊天、斗图、学习、交流,伸手党勿进

img img
葬爱代码家族群 林间有风团队官方交流
葬爱家族QQ交流群 林间有风团队官方QQ交流群

✨ 亮点

  • 基于原生的 Flask 构建 RESTful API
  • 更灵活的 API文档生成方式(可带 Token)
  • AOP(面向切面编程)设计,实现 参数校验层 & 异常统一处理层
  • Ubuntu 16.04上 Nginx + Gunicorn + Pipenv部署

🔩 内置

  1. 用户管理:提供用户的相关配置
  2. 权限组(角色)管理:接口权限分配和菜单权限分配
  3. 菜单管理:实现后端配置菜单动态路由,支持多级菜单
  4. 字典管理:维护系统中经常使用的字典数据,如:性别,状态
  5. 参数管理:系统动态配置常用参数,如:分页数,前端主题色等
  6. 通知管理:系统通知&公告信息的发布维护
  7. 日志管理:操作日志和登录日志
  8. 接口文档:根据业务代码自动生成相关的api接口文档(Swagger风格)
  9. 错误码:前后端开发的错误码的约定
  10. 文件管理和上传:文件夹和文件的管理
  11. 文章管理

目录

开发工具

  • Python 3.6(虚拟环境:pipenv)
  • MySQL
  • PyCharm(开发工具)
  • Navicat(数据库可视化管理工具)

开发环境搭建

  • MySQL安装、运行,数据库的导入
  • Python 3.6

MySQL的安装和数据导入

一、安装

$ sudo apt-get install mysql-server

安装过程中,会让你输入密码。
请务必记住密码!
务必记住密码!
记住密码!

查看是否安装成功

$ sudo netstat -tap | grep mysql

二、运行

$ mysql -u root -p # 执行完毕后输入密码
$ mysql -u root -p123456 # 直接输入密码,进入(我的密码是: 123456)

-u 表示选择登陆的用户名, -p 表示登陆的用户密码
上面命令输入之后,会提示输入密码(Enter password)

三、导入

下载 MySQL数据 SQL文件

mysql的每条执行以「分号」结尾

mysql> create database zerd; # 建立数据库(zerd)
mysql> use zerd; # 进入该数据库
mysql> source /home/ubuntu/mini-shop-server/zerd.sql; # 导入「mini-shop-server」目录下的sql文件

Tips: 其他数据库操作

// 1. 获取存在的所有表
show tables; 
// 2. 导入成功,可以直接查询(user表)
mysql> select * from user;
// 3. 删除数据库(zerd库)
mysql> drop database zerd;
// 4. 导出数据库
mysql> 

Python3.6版本的安装

查询本地的python3的版本 $ python3 --version 如果不是python3.6的版本,则如下操作

$ sudo apt-get update 
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:jonathonf/python-3.6 
$ sudo apt-get install python3.6

pipenv的安装

如果还未安装pip3包管理工具,请先执行如下语句
$ sudo apt install python3-pip

安装 pipenv
$ pip3 install pipenv

Tips: 其他 pipenv操作

$ pipenv install flask # 安装指定模块,并写入到 Pipfile中
$ pipenv install flask==1.0.2 # 安装指定版本的模块
$ pipenv uninstall flask # 卸载指定模块
$ pipenv update flask # 更新指定模块
$ pip list # 查看安装列表
$ pipenv graph # 查看安装列表,及其相应的以来
$ pipenv --venv # 虚拟环境信息
$ pipenv --py # Python解释器信息
$ pipenv --rm # 卸载当前虚拟环境
$ exit # 退出当前虚拟环境

本地启动

$ git clone https://github.com/Allen7D/mini-shop-server.git
$ cd mini-shop-server 
$ mkdir .venv # 生成.venv文件夹,用于存放该项目的python解释器(包括后续所有安装的包依赖)
$ pipenv --python 3.6 # 指定某 Python 版本创建环境
$ pipenv shell # 激活虚拟环境 or 如果没有虚拟环境,则构建新的(默认版本)
$ pipenv install # 安装包依赖
$ python server.py run # 启动方式1:默认5000端口
$ python server.py run -p 8080 # 启动方式2:改为8080端口
$ python server.py run -h 0.0.0.0 -p 8080 # 启动方式3:以本地IP地址访问

生成临时管理员信息

$ python fake.py

Pycharm的配置[1]

Pycharm中 配置 Pipenv生成的虚拟环境,并使用 指定端口 开启「Debug模式」

  1. 获取该虚拟环境下 Python的解释器的路径
img
  1. 配置指定端口号 Run > Edit Configurations
    写入 run -h 0.0.0.0 8080
    等同于,在终端执行 python server.py run -h 0.0.0.0 -p 8080
img
  1. 开启 Debug Run > Debug 'server'

目录结构

展开查看

.
├── app
│   ├── __init__.py
│   ├── api
│   │   ├── v1          # v1的API接口
│   │   │   ├── __init__.py
│   │   │   ├── address.py  # 用户地址
│   │   │   ├── banner.py   # 推广横幅
│   │   │   ├── category.py # 分类
│   │   │   ├── client.py
│   │   │   ├── order.py    # 订单
│   │   │   ├── pay.py      # 支付
│   │   │   ├── product.py  # 产品
│   │   │   ├── theme.py    # 主题
│   │   │   ├── token.py    # 令牌
│   │   │   └── user.py     # 用户
│   │   └── v2 # v2的API接口
│   │       ├── __init__.py
│   │       └── file.py     # 文件上传
│   ├── api_docs        # 对应的 API文档
│   ├── config # 配置文件
│   │   ├── secure.py
│   │   ├── setting.py
│   │   └── wx.py
│   ├── libs # 自己的库
│   │   ├── enums.py
│   │   ├── error.py
│   │   ├── error_code.py
│   │   ├── httper.py
│   │   ├── limiter.py
│   │   ├── redprint.py
│   │   ├── scope.py
│   │   ├── swagger_filed.py
│   │   ├── token_auth.py
│   │   └── utils.py
│   ├── models          # Model 层
│   ├── service # Service 层
│   │   ├── __init__.py
│   │   ├── app_token.py
│   │   ├── order.py
│   │   ├── pay.py
│   │   ├── token.py
│   │   └── wx_token.py
│   ├── validators      # 参数校验层
│   │   ├── __init__.py
│   │   ├── base.py
│   │   ├── forms.py
│   │   └── params.py
│   ├── web             # 网页文件
│   │   ├── __init__.py
│   │   └── auth.py
│   └── app.py
├── fake.py             # 生成临时用户
├── server.py           # 启动程序(项目入口)
├── config.ini
├── Pipfile             # 包依赖文件
├── code.md             # 错误码(用于前后端开发)
├── README.md           # 项目说明文档
├── zerd.sql
└── LICENSE

开发思路

业务逻辑主要放在 Model 层

img

项目架构体系

业务逻辑分成

DAO层(数据访问层),全称为data access object
属于一种比较底层,比较基础的操作,对于数据库的操作,具体到对于某个表的增删改查。
DAO一定是和数据库的某一张表一一对应的,其中封装了增删改查基本操作,建议DAO只做原子操作,增删改查。

Service层(服务层)
是对一个或多个DAO进行的再次封装,封装成一个服务,因此不只是一个原子操作,需要事务控制。

Controller层(业务层)
管理用户的操作,用户界面传过的请求,调用对应的服务(service),完成用户请求的处理.

自动生成 api 接口文档

Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful风格的 Web 服务。

本项目使用 Flasgger库自动生成 Swagger 风格(Demo)的API文档。

  1. Swagger Editor 在网页端直接编辑 API 文档

查阅 API文档(本项目)

启动服务(DEBUG 模式下)
在浏览器端输入:http://localhost:8080/apidocs/#/

使用 Token

基于 HTTPBasicAuth 来传递token
所以, Postman 中 Authorization 设置使用 Basic Auth;
Flassger 中 securityDefinitions 设置使用 basicAuth (详见config/setting.py)

服务器部署

本项目选择在 Ubuntu 16.04 上,用 Nginx + Gunicorn + Pipenv 部署[3],其中 Gunicorn 取代 uWsgi。

Flask 与 uWsgi 结合有许多难以处理的 bug

运行

gunicorn -w 4 -b 127.0.0.1:8080 server:app # 在8080端口开启 gunicorn
fuser -k 8080/tcp # 关闭占用8080端口的服务

本地&线上同步推进

业务场景

本地与线上的 Swagger API 文档的接口的地址是不同的,但都依赖同一个配置文件 app\config\setting.py
而个人项目有着本地和线上同步,开发和测试同步的需求,会不断修改 app\config\setting.py 文件。

解决

本地线上 自动根据所处的环境变量「ENV_MODE」决定,选择不同的配置文件。

  • 'dev:local'(local development 本地开发环境)
  • 'dev'(development 开发环境 )
  • 'prod'(product 生产环境)
img
  1. PyCharm的状态栏的「Run > Edit Configurations」中编辑环境变量
  2. 设置ENV_MODE=dev:local
  3. 代码

上传&下载

上传[2]

具体查看 app/api/v2/file.pyupload_file 视图函数

下载

1. 「静态资源文件」下载

默认下载路径前缀 http://0.0.0.0:8080/static/ 访问 app/static/images 目录下的资源

http://0.0.0.0:8080/static/images/[email protected]

访问 app/static/files 目录下的资源

http://0.0.0.0:8080/static/files/Python面向对象编程指南.epub

###对第三方库的装饰器的扩展 具体查看 app/lib/redprint.pydoc 函数

不改动第三方库 Flasgger的 swag_from(装饰器函数)的源码,对其进行了功能的扩展

Nginx 部署

$ nginx -s stop # 停止 nginx
$ nginx -s reload # 重启 nginx

Nginx 配置

建立 文件A 快捷方式 文件B : ln –s 源文件A 目标文件B
/etc/nginx/sites-available/server 为源文件,以 /etc/nginx/sites-enabled/server 为目标文件,使得2个文件同步。
ln -s /etc/nginx/sites-available/server /etc/nginx/sites-enabled/server

/etc/nginx/sites-available/server 配置如下:

server {
    listen 443 default;
    server_name www.ivinetrue.com ivinetrue.com; 
    ssl on;
    root html;
    index index.html index.htm;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    ssl_certificate cert/ivinetrue.pem;
    ssl_certificate_key cert/ivinetrue.key;
    ssl_session_timeout 10m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/workspace/mini-shop-server/server.sock;
        # proxy_pass http://127.0.0.1:8080; # 弃用
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_headers_hash_max_size 51200;
        proxy_headers_hash_bucket_size 6400;
    }
    location /static/ {
        alias /home/workspace/mini-shop-server/app/static/; # 静态资源文件路径
    }

}

server {
      listen  80;
      server_name www.ivinetrue.com ivinetrue.com;
      rewrite ^(.*)$  https://$host$1 permanent; # https 代理
}

Nginx 其他配置

Nginx 的公共配置(例如: gzip)需要修改 /etc/nginx/nginx.conf

supervisor 配置

路径 /etc/supervisor/conf.d/server.conf

配置文件

[program:server]
environment=PATH='/root/.local/share/virtualenvs/server-4o3oDD8t/bin/python'
command = /root/.local/share/virtualenvs/server-4o3oDD8t/bin/gunicorn -w 4 -b unix:/home/workspace/morning-star/server/server.sock server:app
directory = /home/workspace/morning-star/server
user = root
#日志输出
stderr_logfile=/tmp/blog_stderr.log
stdout_logfile=/tmp/blog_stdout.log

运行supervisorctl restart server

使用

第一步:

第二步:

第三步:

后续

三端分离

1.客户端: mini-shop-wx

微信小程序n链接

2.服务端: mini-shop-server

基于 Flask框架构建 RESTful API。

点击查阅 API文档(Swagger风格)

3.CMS: mini-shop-cms

基于 Vue.js框架和Element-UI组件库 链接

Python3 学习路线(亲测)

路线: 1 -> 2 -> 3 -> 4

  1. 《全面系统 Python3 入门+进阶课程》
  2. 《Python Flask 高级编程》
  3. 《Python Flask 构建可扩展的 RESTful API》
  4. 《微信小程序商城构建全栈应用》

参考

【1】PyCharm配置使用Flask-Script启动以及开启Debug模式

【2】Flask 上传文件

【3】Flask + Gunicorn + Nginx 部署

【4】centos7 下通过nginx+uwsgi部署django应用

【5】Nginx的https配置记录以及http强制跳转到https的方法梳理

【6】Nginx配置HTTPS

【7】Linux下导入、导出mysql数据库命令的实现方法

【8】Automatically enable HTTPS on your website with EFF's Certbot.

【9】ubuntu16.04 64bit 升级 python3.5 python3.6

【10】Lin-CMS:优秀的 Flask & Vue 结合的前后端分离的 CMS 解决方案

【11】基于Linux环境搭建Nginx+uWSGI+Python框

mini-shop-server's People

Contributors

735946969 avatar allen7d avatar bidoli avatar mohansd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mini-shop-server's Issues

web端网页验证的问题

我使用了mini-shop-server的后端,管理前端用的是lin-cms-vue-0.2.x,
遇到的问题是,登录后,获取需要权限的数据(@auth.login_required)提示“UNAUTHORIZED”,
我按照小程序里的格式添加了请求头也是无效的。
有什么解决方法吗?
axios.js:

        var header = {
          'content-type': 'application/json',
          'authorization': `Basic ${Base64.encode(`${accessToken}:$`)}`
        }
        reqConfig.headers = header

另外,请教一下,小程序请求头中为什么要base64encode呢?

sqlalchemy 字段中设置默认值为UrlFromEnum.LOCAL 不能正确create

UrlFromEnum.LOCAL 来自配置文件中设置的变量 来源: 1 本地,2 公网

from app.libs.enums import UrlFromEnum

class File(Base):
tablename = 'file'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, comment='父级目录id')
uuid_name = Column(String(100), comment='唯一名称')
name = Column(String(100), nullable=False, comment='原始名称')
path = Column(String(500), comment='路径')
extension = Column(String(50), comment='后缀')
_from = Column('from', SmallInteger, default=file_from, comment='来源: 1 本地,2 公网')

在上传文件接口

uploader = LocalUploader(files) # 或者导入,使用 QiniuUploader
uploader.locate(parent_id=id)
res = uploader.upload()

uploader方法中

File.create(
parent_id=self.parent_id,
name=single.filename,
uuid_name=uuid_filename,
path=relative_path,
extension=self._get_ext(single.filename),
size=self._get_size(single),
md5=file_md5
)

失败,报错

image

错误日志如下:

127.0.0.1 - - [02/Mar/2021 11:57:34] "POST /cms/file/1 HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\werkzeug\middleware\proxy_fix.py", line 169, in call
return self.app(environ, start_response)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 1822, in handle_user_exception
return handler(e)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app_init_.py", line 128, in framework_error
raise e
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\flasgger\utils.py", line 248, in wrapper
return function(*args, **kwargs)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app\extensions\api_docs\redprint.py", line 59, in wrapper
return f(*args, **kwargs)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app\api\cms\file.py", line 46, in upload_file
res = uploader.upload()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app\extensions\file\local_uploader.py", line 49, in upload
md5=file_md5
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app\core\db.py", line 162, in create
return instance.save(commit)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\app\core\db.py", line 176, in save
db.session.commit()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\scoping.py", line 163, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 1042, in commit
self.transaction.commit()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 504, in commit
self._prepare_impl()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 483, in _prepare_impl
self.session.flush()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 2536, in flush
self._flush(objects)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 2678, in _flush
transaction.rollback(capture_exception=True)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in exit
with_traceback=exc_tb,
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\util\compat.py", line 182, in raise

raise exception
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\session.py", line 2638, in _flush
flush_context.execute()
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 422, in execute
rec.execute(self)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 589, in execute
uow,
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\persistence.py", line 245, in save_obj
insert,
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\orm\persistence.py", line 1136, in _emit_insert_statements
statement, params
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\base.py", line 1011, in execute
return meth(self, multiparams, params)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\sql\elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\base.py", line 1130, in _execute_clauseelement
distilled_params,
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\base.py", line 1317, in execute_context
e, statement, parameters, cursor, context
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\base.py", line 1514, in handle_dbapi_exception
util.raise
(exc_info[1], with_traceback=exc_info[2])
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\util\compat.py", line 182, in raise

raise exception
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\base.py", line 1277, in _execute_context
cursor, statement, parameters, context
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\sqlalchemy\engine\default.py", line 593, in do_execute
cursor.execute(statement, parameters)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\cymysql\cursors.py", line 117, in execute
escaped_args = tuple(conn.escape(arg) for arg in args)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\cymysql\cursors.py", line 117, in
escaped_args = tuple(conn.escape(arg) for arg in args)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\cymysql\connections.py", line 306, in escape
return escape_item(obj, self.charset, self.encoders)
File "C:\Users\57137\Desktop\微信小程序\小程序后端\mini-shop-server-dev\f-venv\lib\site-packages\cymysql\converters.py", line 327, in escape_item
return encoderstype(val)
KeyError: <enum 'UrlFromEnum'>

raise BadRequest("Failed to decode JSON object: {0}".format(e))

req_body = request.get_json() if request.get_json() else {}
这里报错(我是在小程序端调用)
raise BadRequest("Failed to decode JSON object: {0}".format(e))
那行加了try···except···后log输出
"path": {}, "query": {}, "body": {}
可能是request没有获得参数?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.