首页 > 解决方案 > Jython 错误:java.util.zip.DataFormatException:设置的代码长度无效

问题描述

当我使用 Python requests 模块进行 API 调用时使用 StreamSets Jython (Python 2.7) 处理器

r = requests.get("https://someurl.com", headers={"Authorization":"Bearer sometokenstring"})

我收到一个错误:

INFO java.util.zip.DataFormatException: invalid code lengths set. 

相同的代码在带有 Python 2.7 的 linux 终端中运行而没有此错误。有什么想法可以解决这个错误吗?

标签: python-requestsjython

解决方案


这通过添加请求标头属性得到解决:“Accept-Encoding”:“deflate”,因为 zip 格式数据导致了一些问题。所以现在请求看起来像:

r = requests.get("https://someurl.com", headers={"Authorization":"Bearer sometokenstring","Accept-Encoding":"deflate"})

推荐阅读