gpt4 book ai didi

python - "' 模块 ' object has no attribute ' SSLContext '"使用 flocker-api 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:27 31 4
gpt4 key购买 nike

这是 flocker api url

https://docs.clusterhq.com/en/latest/reference/api.html

我尝试使用 httplib 建立 https 连接,但我无法通过 ssl 验证 [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:765)

顺便说一句:它显示错误:

AttributeError: 'module' object has no attribute 'SSLContext'

我的 python 版本是 2.7.6,但是如果我使用 python 2.7.5 它会通过。

最佳答案

我自己解决了我的问题,这是我的代码

import httplib
import ssl
import json
import socket
httpsConn = None
# KEY_FILE = "/etc/flocker/scio01.key"
# CERT_FILE = "/etc/flocker/scio01.crt"
# CA_FILE = "/etc/flocker/cluster.crt"

KEY_FILE = "/root/lichao_test/scio01.key"
CERT_FILE = "/root/lichao_test/scio01.crt"
CA_FILE = "/root/lichao_test/cluster.crt"

HOST = "192.168.9.14"
PORT = 4523
body = {
"dataset_id": "a1234567-3fb9-4c1a-81ce-efeeb9f2c788",
"primary": "c1234567-17b2-4812-beca-1434997d6c3f",
"metadata": {
"name": "demo",
"owner": "lichao"
},
"maximum_size": 67108864
}

try:
httpsConn = httplib.HTTPSConnection(HOST, PORT)
sock = socket.create_connection((HOST, PORT))
try:
httpsConn.sock = ssl.wrap_socket(sock, ca_certs=CA_FILE, keyfile=KEY_FILE, certfile=CERT_FILE,
cert_reqs=ssl.CERT_REQUIRED, ssl_version=ssl.PROTOCOL_SSLv3)
json_body = json.dumps(body)
# httpsConn.request(method="POST", url="https://192.168.9.14:4523/v1/configuration/datasets",
# headers={"Content-type": "application/json", 'Connection': 'keep-alive'}, body=json_body)
httpsConn.request(method="GET",url="/v1/configuration/datasets",headers={"Content-type": "application/json", 'Connection': 'keep-alive'})

res = httpsConn.getresponse()
body = res.read()
status = res.status
print "-" * 70
print status, body
except ssl.SSLError, e:
print "Trying SSLv23.",e
except Exception, e:
import traceback

print traceback.format_exc()

关于python - "' 模块 ' object has no attribute ' SSLContext '"使用 flocker-api 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39651998/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com