python telnetlib open 超时时间_Python的请求超时值误差

Good Evening,

I cannot get my https request to go through. I'm having to use SSLv3, so I'm specifying the protocol with:

import requests

from requests.adapters import HTTPAdapter

from urllib3.poolmanager import PoolManager

import ssl

class MyAdapter(HTTPAdapter):

def init_poolmanager(self, connections, maxsize, block=False):

self.poolmanager = PoolManager(num_pools=connections,

maxsize=maxsize,

block=block,

ssl_version=ssl.PROTOCOL_SSLv3)

username = 'username'

password = 'password'

email = 'email@example.com'

url = 'https://api.example.com/'

headers = {'Accept': 'application/json', 'content-type': 'application/json'}

params = {'emailaddress': email}

auth = (username, password)

s = requests.Session()

s.mount(url, MyAdapter())

r = s.get(url+'customer.svc/search', params=params, auth=auth, headers=headers)

When I run my get request I get the following error:

Traceback (most recent call last):

File "", line 1, in

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/requests/sessions.py", line 473, in get

return self.request('GET', url, **kwargs)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/requests/sessions.py", line 461, in request

resp = self.send(prep, **send_kwargs)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/requests/sessions.py", line 573, in send

r = adapter.send(request, **kwargs)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/requests/adapters.py", line 370, in send

timeout=timeout

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/urllib3/connectionpool.py", line 517, in urlopen

timeout_obj = self._get_timeout(timeout)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/urllib3/connectionpool.py", line 283, in _get_timeout

return Timeout.from_float(timeout)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/urllib3/util/timeout.py", line 152, in from_float

return Timeout(read=timeout, connect=timeout)

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/urllib3/util/timeout.py", line 95, in __init__

self._connect = self._validate_timeout(connect, 'connect')

File "/home/ubuntu/workspace/app/venv/lib/python2.7/site-packages/urllib3/util/timeout.py", line 125, in _validate_timeout

"int or float." % (name, value))

ValueError: Timeout value connect was Timeout(connect=None, read=None, total=None), but it must be an int or float.

Any ideas? I can't figure it out.

Additional Context: I'm on an Amazon EC2 Ubuntu Instance, running requests 2.5.1 and python 2.7.6

解决方案

Looks like requests doesn't always play nice when you bring in an outside urllib3 distribution. What I ended up doing was calling requests internal urllib3 instead.

from requests.packages.urllib3.poolmanager import PoolManager

instead of:

from urllib3.poolmanager import PoolManager

No issues since I started doing this.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值