2014-01-22 109 views
1

我正在嘗試使用可用於gerrit版本2.6的REST API。下面是我的代碼:使用gerrit REST API

import httplib 
import urllib 

conn = httplib.HTTPSConnection("<server-name>:<port-number>") 
args=urllib.urlencode({'userName':'USER', 'password':'PASSWORD'}) 
headers={'Content-type':'application/json', 'Accept':'application/json'} 
r1 = conn.request("post", "https://stackoverflow.com/a/changes", args) 
r2 = conn.getresponse() 


print r1,r2.status,r2.reason,r2 

當我運行它,我得到以下錯誤「

Traceback (most recent call last): 
File "./RestApi.py", line 10, in <module> 
r1 = conn.request("post", "https://stackoverflow.com/a/changes", args) 
File "/usr/lib/python2.7/httplib.py", line 958, in request 
self._send_request(method, url, body, headers) 
File "/usr/lib/python2.7/httplib.py", line 992, in _send_request 
self.endheaders(body) 
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders 
self._send_output(message_body) 
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output 
self.send(msg) 
File "/usr/lib/python2.7/httplib.py", line 776, in send 
self.connect() 
File "/usr/lib/python2.7/httplib.py", line 1161, in connect 
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file) 
File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket 
ciphers=ciphers) 
File "/usr/lib/python2.7/ssl.py", line 143, in __init__ 
self.do_handshake() 
File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake 
self._sslobj.do_handshake() 
ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol 

還有沒有其他的方法可以讓我得到這個工作???

回答

2

的SSL連接你的服務器甚至不工作:

套路:SSL23_GET_SERVER_HELLO:未知協議

所以你甚至沒有達到格里特。

Gerrit面前有SSL代理嗎?你能用你的瀏覽器連接到https://<server-name>:<port-number>嗎?

如果你不使用SSL,那麼你不應該使用httplib.HTTPSConnection,但可能httplib.HTTPConnection連接。