2016-08-09 79 views
4

我寫了一個非常小的python客戶端來訪問confluence restful api。我正在使用https協議來連接合流。我遇到了Connection reset by peer錯誤。 以下是完整的堆棧跟蹤。Python客戶端錯誤'連接重置對等'

/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. 
    SNIMissingWarning 
/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. 
    InsecurePlatformWarning 
Traceback (most recent call last): 
    File "wpToConfluence.py", line 15, in <module> 
    main() 
    File "wpToConfluence.py", line 11, in main 
    headers={'content-type': 'application/json'}) 
    File "/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/api.py", line 71, in get 
    return request('get', url, params=params, **kwargs) 
    File "/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/api.py", line 57, in request 
    return session.request(method=method, url=url, **kwargs) 
    File "/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/sessions.py", line 475, in request 
    resp = self.send(prep, **send_kwargs) 
    File "/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/sessions.py", line 585, in send 
    r = adapter.send(request, **kwargs) 
    File "/Users/rakesh.kumar/.virtualenvs/wpToConfluence.py/lib/python2.7/site-packages/requests/adapters.py", line 453, in send 
    raise ConnectionError(err, request=request) 
requests.exceptions.ConnectionError: ('Connection aborted.', error(54, 'Connection reset by peer')) 

這裏是我的客戶端代碼:

import requests 


def main(): 
    auth = open('/tmp/confluence', 'r').readline().strip() 

    username = 'rakesh.kumar' 

    response = requests.get("https://<HOST-NAME>/rest/api/content/", 
          auth=(username, auth), 
          headers={'content-type': 'application/json'}) 
    print response 

if __name__ == "__main__": 
    main() 

我運行該腳本在虛擬環境和下面的軟件包安裝在這樣的環境:

(wpToConfluence.py)➜ Python pip list 
You are using pip version 6.1.1, however version 8.1.2 is available. 
You should consider upgrading via the 'pip install --upgrade pip' command. 
appnope (0.1.0) 
backports.shutil-get-terminal-size (1.0.0) 
decorator (4.0.10) 
ipdb (0.10.1) 
ipython (5.0.0) 
ipython-genutils (0.1.0) 
pathlib2 (2.1.0) 
pexpect (4.2.0) 
pickleshare (0.7.3) 
pip (6.1.1) 
prompt-toolkit (1.0.5) 
ptyprocess (0.5.1) 
Pygments (2.1.3) 
requests (2.10.0) 
setuptools (25.1.6) 
simplegeneric (0.8.1) 
six (1.10.0) 
traitlets (4.2.2) 
urllib3 (1.16) 
wcwidth (0.1.7) 

它不會埋怨蟒蛇版本號,但我不知道如何更新我的Mac /虛擬環境python。

我試圖蜷縮命令和郵遞員他們兩個對於給定的參數工作正常。

+0

鍵入密碼文件中的硬編碼,然後再試一次解決它。它確實抱怨你的點是舊的。你可以用'sudo pip install --upgrade pip'來更新它 –

+0

@DoronCohen 我已經將pip升級到了'8.1.2'版本。我使用這個命令來解決這個問題'pip安裝'請求[安全]「,它的工作就像魅力。 – Rakesh

+0

太好了。發佈解決方案,然後 –

回答

13

安裝requests庫時,它跳過了幾個爲SSL/Https連接所需的optional security packages('pyOpenSSL','ndg-httpsclient'和'pyasn1')。 您可以通過運行此命令

pip install "requests[security]" 

pip install pyopenssl ndg-httpsclient pyasn1