为了账号安全,请及时绑定邮箱和手机立即绑定

Session.send()报错

def hard_request():
    from requests import Request, Session
    s = Session()
    headers = {'User-Agent': 'fake1.3.4'}
    req = Request('GET', build_url('user/emails'), auth=('imoocdemo', 'imoocdemo123'), headers=headers)
    prep = req.prepare()
    print prep.body
    print prep.headers
    
    resp = s.send(prep, timeout=10)
    print resp.status_code
    print resp.headers
    print resp.text


输出结果:

None

{'Authorization': 'Basic aW1vb2NkZW1vOmltb29jZGVtbzEyMw==', 'User-Agent': 'fake1.3.4'}

Traceback (most recent call last):

  File "C:/Users/10234881/PycharmProjects/test/requests_demo/github_api.py", line 63, in <module>

    hard_request()

  File "C:/Users/10234881/PycharmProjects/test/requests_demo/github_api.py", line 53, in hard_request

    resp = s.send(prep, timeout=10)

  File "C:\Python27\lib\site-packages\requests-2.21.0-py2.7.egg\requests\sessions.py", line 646, in send

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

  File "C:\Python27\lib\site-packages\requests-2.21.0-py2.7.egg\requests\adapters.py", line 504, in send

    raise ConnectTimeout(e, request=request)

requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /user/emails (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x040BD290>, 'Connection to api.github.com timed out. (connect timeout=10)'))


正在回答

3 回答

requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /user/emails (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x040BD290>, 'Connection to api.github.com timed out. (connect timeout=10)'))

超时!!写的很清楚

0 回复 有任何疑惑可以回复我~
  1. 看你发出来的代码没有发现有什么问题。看看是不是别处的代码导致的报错

  2. 报错信息是连接超时。检查下你的网络,看看是不是网络问题

  3. 由于github的特殊原因,可能会响应超时。多试几次

  4. 问: 你的报错信息是`requests.exceptions.ConnectTimeout`,为什么你说是Session.send()报错?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Python-走进Requests库
  • 参与学习       38752    人
  • 解答问题       106    个

python类库中,requests是一件利器,想深入了解一起来学吧

进入课程

Session.send()报错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信