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
還有沒有其他的方法可以讓我得到這個工作???