导致异常的Python请求的超时参数

时间:2016-02-19 00:28:29

标签: python python-requests

我有一些请求代码,这些代码允许我的代码在超时之前的一段时间后重试URL一定次数:

import requests

s = Session()
s.mount('http://www.example.com/', HTTPAdapter(
max_retries=Retry(total=50, status_forcelist=
[400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418,
421, 422, 423, 424, 425, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511])
)
)

url = 'www.example.com/somepage'

params = {'param1': '1', 'param2': '2'}

headers = {'someheader': 'header'}

response = s.get(url, params=params, headers=headers, timeout=60)

然而,这导致了以下错误,我不确定其原因。谁能告诉我为什么会这样?

Traceback (most recent call last):
  File "C:\Python27\ExampleScript.py", line 244, in examplefunction
    response = s.get(url, params=params, headers=headers, timeout=60)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in get
    return self.request('GET', url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 327, in send
    timeout=timeout
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 558, in urlopen
    "broken by '%r': %s" % (retries, err, url))
TypeError: %d format: a number is required, not Retry

由于

0 个答案:

没有答案