zoukankan      html  css  js  c++  java
  • python3 zlib.error: Error -3 while decompressing data: invalid distance too far back

    客户端上报的数据中有gzip压缩加urlencode加base64encode

    服务端python逆向解析的时候偶发出现python3 zlib.error: Error -3 while decompressing data: invalid distance too far back,

    出现这个问题一般都是数据转化过程中出现问题

        s2 = parse.unquote(s1.decode('utf-8'))
        s3 = s2.encode('ISO-8859-1')
        return gzip.decompress(s3)
    

      对应python中的代码是这样的,通过答应java和python的s3数据的时候发现两边的数据中有几行不相同, java这边打印的ord 是43, python这边是32, 43和32分别对应的字符是‘+’和‘ ’

    我在unquote完之后替换掉+为‘ ’ , 发现还是偶发同样的错误, 只不过概率变低了, 所以知道自己的方向是对的, 只不过还有些地方有问题, 接着看python的源码, 发现相同包下还有一个

    def unquote_plus(string, encoding='utf-8', errors='replace'):
        """Like unquote(), but also replace plus signs by spaces, as required for
        unquoting HTML form values.
    
        unquote_plus('%7e/abc+def') -> '~/abc def'
        """
        string = string.replace('+', ' ')
        return unquote(string, encoding, errors)
    

      顿时感觉这就是能解决问题的方法, 用个方法验证后果然解决了问题

    发现是自己替换字符串的顺序不对, 应该在decode之前去替换, 很尴尬, 记录下这个方法, 下次发现如果有urlencode 和其他语言不一致的情况下优先替换成plus方法试一下

  • 相关阅读:
    Spark面对OOM问题的解决方法及优化总结 (转载)
    spark rdd 宽窄依赖理解
    hive orc update
    hive sql 语句执行顺序及执行计划
    java 正则 贪婪匹配 匹配sql语句中的引号内容
    java 权重随机算法实现
    MySQL创建用户和加限权
    MySQL完整性约束
    MySQL基础操作与数据类型
    MySQL数据库初识
  • 原文地址:https://www.cnblogs.com/leescre/p/13068500.html
Copyright © 2011-2022 走看看