I am trying to use REST APIs which are available with gerrit version 2.6. Below is my code:
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", "/a/changes", args)
r2 = conn.getresponse()
print r1,r2.status,r2.reason,r2
When I run it , I get below errors "
Traceback (most recent call last):
File "./RestApi.py", line 10, in <module>
r1 = conn.request("post", "/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
Is there any other way I can get this working???
The SSL connection to your server doesn't even work:
routines:SSL23_GET_SERVER_HELLO:unknown protocol
So you don't even reach Gerrit.
Do you have an SSL proxy in front of Gerrit? Can you connect with your browser to https://<server-name>:<port-number>
?
If you don't use SSL, then you shouldn't use httplib.HTTPSConnection
, but probably httplib.HTTPConnection
connection.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.