gpt4 book ai didi

python-2.7 - python : reading from rfile in SimpleHTTPRequestHandler

转载 作者:行者123 更新时间:2023-12-05 08:09:58 28 4
gpt4 key购买 nike

在重载 SimpleHTTPRequestHandler 时,我的函数在 self.rfile.read() 上阻塞。读取前如何查看rfile中是否有数据?或者,是否存在在缺少数据时返回的非阻塞读取调用?

最佳答案

作为记录,解决方案是只尝试读取 header Content-Length 中指定的字节数。即类似于:

contentLength = int(request.headers['Content-Length'])
payload = str(request.rfile.read(contentLength))

关于python-2.7 - python : reading from rfile in SimpleHTTPRequestHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048383/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com