75

解决: Python-aiohttp.ClientPayloadError:Response payload is not completed

 2 years ago
source link: https://viencoding.com/article/72
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python-aiohttp.ClientPayloadError:Response payload is not completed

使用aiohttp时,遇到异常aiohttp.ClientPayloadError:Response payload is not completed


关于异常的官方文档:

class aiohttp.ClientPayloadError
This exception can only be raised while reading the response payload if one of these errors occurs:
1.invalid compression
2.malformed chunked encoding
3.not enough data that satisfy Content-Length HTTP header.

Derived from ClientError

也就是说三种情况,一个是非法的压缩格式,一个是错误的chunk编码,然后是数据不足Content-length的大小。

通常为Accept-Encoding:gzip, deflate, br ,也就是三种编码格式。但其实,aiohttp默认没有br解码,需要安装依赖,详细说明请看下文。


官方文档说明如下:

  • The gzip and deflate transfer-encodings are automatically decoded for you.
  • You can enable brotli transfer-encodings support, just install brotlipy.

也就是说,默认情况下,aiohttp可以自动解码gzip和deflate格式,而brotlipy格式的需要安装依赖包。

pip install brotlipy

通常安装了之后就可以解码br格式了。


作者博客:vien.tech

viencoding.com版权所有,允许转载,但转载请注明出处和原文链接: https://viencoding.com/article/72 欢迎小伙伴们在下方评论区留言 ~ O(∩_∩)O
文章对我有帮助, 点此请博主吃包辣条 ~ O(∩_∩)O


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK