阿里云函数计算GBK编码

阿里云函数计算GBK编码

前端树莓派,需要后端处理编码问题;

参考文档阿里文档:"https://help.aliyun.com/zh/functioncompute/fc-2-0/user-guide/configure-an-api-gateway-trigger?spm=a2c4g.11186623.help-menu-2508973.d_2_8_19_1.de5c36d4D0LuA6"

修改属性,在线函数调试成功

# 正常代码

CJsonEncoder 是处理时间的,可以移除该属性

python 复制代码
    def SUCESEE(self, data):
        if data is None:
            data = {}
        rep = {
            'isBase64Encoded': 'false',
            'statusCode': '200',
            'headers': {'x-custom-header': 'no', 'Content-Type': 'application/json;charset=UTF-8'},
            'body': {'code': 10000, 'msg': 'Success', 'data': data}
        }
        return json.dumps(rep, cls=CJsonEncoder)

GBK编码代码

python 复制代码
     # 返回GBK编码-中控屏使用(不推送,仅存档)
    def GBK_DATA(self, data):
        rep = {
            'isBase64Encoded': 'false',
            'statusCode': '200',
            'headers': {'x-custom-header': 'no', 'Content-Type': 'text/html; charset=GBK'},  # GBK-代码
            'body': {'code': 10000, 'msg': 'Success', 'data': data}
        }
        rep['body'] = json.dumps(rep['body'], cls=CJsonEncoder, ensure_ascii=True).encode('GBK').decode('latin1')  # GBK-代码
        return json.dumps(rep, cls=CJsonEncoder)

效果

相关推荐
wanhengidc14 小时前
云手机的出现意味着什么
运维·服务器·web安全·智能手机·云计算
AKAMAI1 天前
从 Cloudflare 服务中断,看建立多维度风险应对机制的必要
人工智能·云原生·云计算
翼龙云_cloud1 天前
阿里云渠道商:如何在NAS控制台创建通用型NAS NFS协议文件系统?
运维·服务器·阿里云·云计算
HUT_Tyne2651 天前
阿里云ACP认证
阿里云·云计算·php
熙客1 天前
阿里云性能测试:PTS的使用
阿里云·云计算
刘国华-平价IT运维课堂1 天前
红帽企业Linux 10.1发布:AI命令行助手、量子安全加密和混合云创新
linux·运维·服务器·人工智能·云计算
翼龙云_cloud1 天前
阿里云渠道商:WordPress网站如何使用文件存储NAS?
运维·服务器·阿里云·云计算
Ryan ZX1 天前
Rook 云原生存储编排系统
ceph·云原生·云计算
算家计算1 天前
解决AI任务排队难题:基于Slurm的优先级调度与资源抢占策略配置详解
人工智能·云计算
Hellc0071 天前
Docker网段与阿里云RDS内网冲突:深度分析与解决方案
阿里云·docker·容器