亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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)'))


正在回答

2 回答

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)'))

超時?。懙暮芮宄?/p>

0 回復 有任何疑惑可以回復我~
  1. 看你發出來的代碼沒有發現有什么問題??纯词遣皇?strong>別處的代碼導致的報錯

  2. 報錯信息是連接超時。檢查下你的網絡,看看是不是網絡問題。

  3. 由于github的特殊原因,可能會響應超時。多試幾次。

  4. 問: 你的報錯信息是`requests.exceptions.ConnectTimeout`,為什么你說是Session.send()報錯?

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

舉報

0/150
提交
取消
Python-走進Requests庫
  • 參與學習       38700    人
  • 解答問題       114    個

python類庫中,requests是一件利器,想深入了解一起來學吧

進入課程

Session.send()報錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號