简体   繁体   English

使用Gerrit REST API

[英]Use of gerrit REST APIs

I am trying to use REST APIs which are available with gerrit version 2.6. 我正在尝试使用gerrit 2.6版提供的REST API。 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: 与服务器的SSL连接甚至无法正常工作:

routines:SSL23_GET_SERVER_HELLO:unknown protocol 例程:SSL23_GET_SERVER_HELLO:未知协议

So you don't even reach Gerrit. 因此,您甚至都没有达到Gerrit。

Do you have an SSL proxy in front of Gerrit? Gerrit前面有SSL代理吗? Can you connect with your browser to https://<server-name>:<port-number> ? 您可以使用浏览器连接到https://<server-name>:<port-number>吗?

If you don't use SSL, then you shouldn't use httplib.HTTPSConnection , but probably httplib.HTTPConnection connection. 如果不使用SSL,则不应使用httplib.HTTPSConnection ,而应使用httplib.HTTPConnection连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM