我将PythonRequests模块(v.2.19.1)与python3.4.3一起使用,调用远程服务器上的一个函数,该函数生成一个.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分钟后超时,错误为:File "/usr/lib/python3/dist-packages/requests/adapters.py", line 330, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 612, in urlopen
raise MaxRetryError(self, url, e)
urllib3.exceptions.MaxRetryError: > HTTPSConnectionPool(host='myremoteserver.com', port=443): Max retries exceeded with url: /directory/jsp/Backup.jsp (Caused by < class 'http.client.BadStatusLine'>: '')
如果我将超时设置为更小的值,比如5秒,我会得到一个非常合理的错误:urllib3.exceptions.ReadTimeoutError:
HTTPSConnectionPool(host='myremoteserver.com', port=443): Read
timed out. (read timeout=5)
如果我从浏览器运行这个进程,它运行得很好,所以看起来不像是远程服务器关闭了连接,或者是防火墙或是介于两者之间的什么东西关闭了连接。在