HTTPS-Verbindung mit dem PEM-Zertifikat

Ich versuche zu POSTEN HTTPS-Anfragen über ein PEM-Zertifikat wie folgt:

import httplib  
CERT_FILE = '/path/certif.pem'
conn = httplib.HTTPSConnection('10.10.10.10','443', cert_file =CERT_FILE)   
conn.request("POST", "/") 
response = conn.getresponse()       
print response.status, response.reason
conn.close()

Habe ich die folgende Fehlermeldung:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.6/httplib.py", line 951, in _send_request
self.endheaders()
File "/usr/lib/python2.6/httplib.py", line 908, in endheaders
self._send_output()
File "/usr/lib/python2.6/httplib.py", line 780, in _send_output
self.send(msg)
File "/usr/lib/python2.6/httplib.py", line 739, in send
self.connect()
File "/usr/lib/python2.6/httplib.py", line 1116, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
File "/usr/lib/python2.6/ssl.py", line 338, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
File "/usr/lib/python2.6/ssl.py", line 118, in __init__
cert_reqs, ssl_version, ca_certs)
ssl.SSLError: [Errno 336265225] _ssl.c:339: error:140B0009:SSL       
routines:**SSL_CTX_use_PrivateKey_file**:PEM lib

Wenn ich entfernen Sie die cert_file von httplib, habe ich die folgende Antwort:

200 ok

Wenn ich den Authentication header (wie empfohlen von MattH) mit leere post-Nutzlast, funktioniert es auch.

Jedoch, wenn ich das gute Anfrage mit dem Pfad, den Körper und den Kopf, wie folgt (ich vereinfacht Ihnen...)

body = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">blablabla</S:Envelope>'
URLprov = "/syncaxis2/services/XXXsyncService"
auth_header = 'Basic %s' %  (":".join(["xxx","xxxxx"]).encode('Base64').strip('\r\n'))
conn.request("POST",URLprov,body,{'Authenticate':auth_header})

Ich habe 401 Unauthorized Antwort !

Wie Sie sehen können, zunächst werde ich aufgefordert, den PrivateKey ! warum brauche ich den PrivateKey, wenn ich einen client ? dann, wenn ich entfernen Sie den PrivateKey und das Zertifikat, und setzen Sie den Pfad/Body/Header habe ich 401 Unauthorized Fehler mit der Meldung " WWW-Authenticate: Basic realm="SYNCNB Realm Server".

Kann man das erklären dieses Problem? Gibt es eine andere Möglichkeit zum senden von HTTPS-request mit einem Zertifikat in Python?

InformationsquelleAutor psikais | 2011-05-05
Schreibe einen Kommentar