阿里云函数计算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)

效果

相关推荐
jingxun1234 小时前
珲春好吃的烤肉
阿里云
孤岛悬城5 小时前
阿里云实战:RuoYi项目上云
云原生·云计算
kingmax542120085 小时前
AWS ML Specialist 考试备考指南
云计算·aws·ai证书·ai认证
顾北1219 小时前
阿里百炼AI大模型接入指南
阿里云·ai编程
@HNUSTer19 小时前
基于 GEE 利用多波段合成的方法高效处理并下载数据——以 MODIS 潜热通量(LE)年均值数据产品下载为例
云计算·数据集·遥感大数据·gee·云平台·modis·潜热通量(le)
weixin_307779131 天前
在AWS上构建类Manus的生产级AI Agent服务
运维·人工智能·云计算·aws·agi
bluetata1 天前
申请 AWS Community Builder 详细指南
云计算·aws
忍冬行者2 天前
Elasticsearch 超大日志流量集群搭建(网关 + 独立 Master + 独立 Data 纯生产架构,角色完全分离,百万级日志吞吐)
大数据·elasticsearch·云原生·架构·云计算
观测云2 天前
AWS Lambda Python 应用可观测最佳实践(DDTrace)
python·云计算·aws
Ydwlcloud2 天前
AWS 2026折扣活动深度解析:寻找最大优惠的智慧路径
大数据·服务器·人工智能·云计算·aws