我正在将表单数据发布到远程计算机上的配置页。以下代码的工作方式是进行远程配置,但是由于某种原因,我收到读取超时错误。
def postData(url, user, password, data, timeout=10):
from requests import Session
from requests.auth import HTTPDigestAuth
session = Session()
response = session.post(
url=url,
auth=HTTPDigestAuth(user, password),
headers={
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept-Language": "en-US,en;q=0.9",
"X-Requested-With": "XMLHttpRequest"
},
data=data,
timeout=timeout
)
return response
我得到的错误是:
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.132.220', port=80): Read timed out. (read timeout=10)
我按如下方式调用该函数:
r = postData(url, usr, pwd, data)
我知道我可以将其包装在try catch块中以处理错误,但我不明白为什么首先会出现ReadTimeout错误。想法?