尽管超时设置,Python请求发布时间超时

问题描述 投票:2回答:1

我在Python 3.4.3中使用Python Requests模块(v.2.1.1.1),在远程服务器上调用函数,生成.csv文件以供下载。一般来说,它完美地运作。有一个特定文件需要> 6分钟才能完成,无论我将timeout参数设置为什么,我都会在尝试生成该文件的5分钟后收到错误。

import requests
s = requests.Session()
authPayload = {'UserName': 'myloginname','Password': 'password'}
loginURL = 'https://myremoteserver.com/login/authenticate'
login = s.post(loginURL, data=authPayload)
backupURL = 'https://myremoteserver.com/directory/jsp/Backup.jsp'
payload = {'command': fileCommand}
headers = {'Connection': 'keep-alive'}
post = s.post(backupURL, data=payload, headers=headers, timeout=None)

错误发生在5分钟后超时:

文件“/usr/lib/python3/dist-packages/requests/adapters.py”,第330行,发送超时=超时

文件“/usr/lib/python3/dist-packages/urllib3/connectionpool.py”,第612行,在urlopen中引发MaxRetryError(self,url,e)

urllib3.exceptions.MaxRetryError:> HTTPSConnectionPool(host ='myremoteserver.com',port = 443):使用url:/directory/jsp/Backup.jsp超出了最大重试次数(由<class'http.client.BadStatusLine'>引起: '')

如果我将超时设置为更小,比如5秒,我会得到一个非常有意义的错误:

urllib3.exceptions.ReadTimeoutError:HTTPSConnectionPool(host ='myremoteserver.com',port = 443):读取超时。 (读取超时= 5)

如果我从浏览器运行该过程,它工作正常,所以它似乎不是关闭连接的远程服务器,或者是关闭连接之间的防火墙或其他东西。

python python-3.x python-requests
1个回答
1
投票

根据OP的要求发表 - 我对原始问题的评论指出了一个相关的SO问题

问题的线索在于http.client.BadStatusLine错误。

请查看以下相关的SO Q & A,它讨论了代理服务器对HTTP请求和响应的影响。

© www.soinside.com 2019 - 2024. All rights reserved.