简体   繁体   English

Python请求ssl [Errno 1] _ssl.c:1428:错误:1408F10B:SSL例程:SSL3_GET_RECORD:版本号错误

[英]Python requests ssl [Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

I'm creating a python app, using requests module. 我正在使用请求模块创建一个python应用程序。 I recently add multiprocessing to speed it up a bit, but I started to get some strange errors like [Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number or [Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac . 我最近添加了多处理以加快它的速度,但我开始得到一些奇怪的错误,如[Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number[Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac The code looks like this: 代码如下所示:

def hometables_one(conn, request, s, hostname, payload, company):
    date1 = request.query.get('date1', '')      
    date2 = request.query.get('date2', '')

    prijmyCelk = 0;
    vydajeCelk = 0;
    neuhrPrijCelk = 0;
    neuhrVydCelk = 0;
    dph = 0;
    dbNazev = company['dbNazev'];
    nazev = company['nazev'];

    if date1 and date2:
        try:
            r = s.get("%s/c/%s/faktura-vydana/(duzpPuv between %s %s)/$sum.json" % (hostname, dbNazev, date1[0], date2[0]), params=payload, verify=False)
            r.raise_for_status()
        except requests.exceptions.RequestException as err:
            #response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
            #return response
            conn.send({ "success": False, "errors": { "reason": str(err)}})
            conn.close()
            return None

    else:
        try:
            r = s.get("%s/c/%s/faktura-vydana/$sum.json" % (hostname, dbNazev), params=payload, verify=False)
            r.raise_for_status()
        except requests.exceptions.RequestException as err:
            #response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
            #return response
            conn.send({ "success": False, "errors": { "reason": str(err)}})
            conn.close()
            return None

    obj_vydana = r.json()
    data_vydana = obj_vydana['winstrom']['sum']['sumDoklUcetni']['values']
    prijmyCelk = float(data_vydana['sumDoklCelkem']['value'])
    neuhrVydCelk = float(data_vydana['sumDoklZbyvaUh']['value'])
    dph_vydane = float(data_vydana['sumDoklDphCelk']['value'])


    if date1 and date2:
        try:
            r = s.get("%s/c/%s/faktura-prijata/(duzpPuv between %s %s)/$sum.json" % (hostname, dbNazev, date1[0], date2[0]), params=payload, verify=False)
            r.raise_for_status()
        except requests.exceptions.RequestException as err:
            #response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
            #return response
            conn.send({ "success": False, "errors": { "reason": str(err)}})
            conn.close()
            return None

    else:
        try:
            r = s.get("%s/c/%s/faktura-prijata/$sum.json" % (hostname, dbNazev), params=payload, verify=False)
            r.raise_for_status()
        except requests.exceptions.RequestException as err:
            #response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
            #return response
            conn.send({ "success": False, "errors": { "reason": str(err)}})
            conn.close()
            return None

    obj_prijata = r.json();
    data_prijata = obj_prijata['winstrom']['sum']['sumDoklUcetni']['values']
    vydajeCelk = float(data_prijata['sumDoklCelkem']['value'])
    neuhrPrijCelk = float(data_prijata['sumDoklZbyvaUh']['value'])
    dph_prijate = float(data_prijata['sumDoklDphCelk']['value'])

    if prijmyCelk != 0:
        result = {
            "corporation": nazev,
            "dbName": dbNazev,
            "prijmyCelk": "%s €" % prijmyCelk,
            "nakladyCelk": "%s €" % vydajeCelk,
            "ziskCelk": "%s €" % (prijmyCelk-vydajeCelk),
            "marzaCelk": ((prijmyCelk-vydajeCelk)/prijmyCelk*100),
            "neuhrVydCelk": "%s €" % neuhrVydCelk,
            "neuhrPrijCelk": "%s €" % neuhrPrijCelk,
            "dph": "%s €" % (dph_vydane-dph_prijate),
        }
    else:
        result = {
            "corporation": nazev,
            "dbName": dbNazev,
            "prijmyCelk": "%s €" % prijmyCelk,
            "nakladyCelk": "%s €" % vydajeCelk,
            "ziskCelk": "%s €" % (prijmyCelk-vydajeCelk),
            "marzaCelk": 0,
            "neuhrVydCelk": "%s €" % neuhrVydCelk,
            "neuhrPrijCelk": "%s €" % neuhrPrijCelk,
            "dph": "%s €" % (dph_vydane-dph_prijate),
        }
    conn.send(result)
    conn.close()
    return None
#####################################################################################

def hometables(request):
    s = requests.Session()
    response = HTTPResponse()
    hostname = request.query.get('hostname', '')[0]
    auth = request.query.get('auth', '')[0]
    p_queue = []
    result = []

    json_r = {"success": True}
    payload = {'authSessionId': request.query.get('auth', '')[0]}
    try:
        r = s.get("%s/c.json" % hostname, params=payload, verify=False)
        r.raise_for_status()
    except requests.exceptions.RequestException as err:
        response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
        return response

    obj = r.json()
    data = obj['companies']['company']
    data = make_list(data)

    parent_conn, child_conn = Pipe()
    for company in data:
        p_queue.append(Process(target=hometables_one, args=(child_conn, request, s, hostname, payload, company))) #create a new process with hometables_one function
        p_queue[-1].start()

    for p in p_queue:
        received_data = parent_conn.recv()
        if "success" not in received_data:
            result.append(received_data)s
            p.join()
        else:
            response.write(ujson.dumps(received_data)) #error in hometables_one function
            return response

    json_r["data"] = result
    response.write(ujson.dumps(json_r))
    return response

In this part 在这一部分

    try:
        r = s.get("%s/c.json" % hostname, params=payload, verify=False)
        r.raise_for_status()
    except requests.exceptions.RequestException as err:
        response.write(ujson.dumps({ "success": False, "errors": { "reason": str(err)}}))
        return response

    obj = r.json()
    data = obj['companies']['company']
            data = make_list(data)

I get a JSON request with all companies currently in system and then I run the hometables_one function for each of them. 我收到了当前处于系统中的所有公司的JSON请求,然后我为每个公司运行了hometables_one函数。 The final data may look like this: 最终data可能如下所示:

[{"createDt":"2014-01-28T00:00:00+01:00","dbNazev":"sveatlo","id":"4","licenseGroup":"null","nazev":"Sveatlo","show":"true","stavEnum":"ESTABLISHED","watchingChanges":"false"}]

or like this: 或者像这样:

[{"createDt":"2014-01-28T00:00:00+01:00","dbNazev":"sveatlo","id":"4","licenseGroup":"null","nazev":"Sveatlo","show":"true","stavEnum":"ESTABLISHED","watchingChanges":"false"},{"createDt":"2014-01-28T00:00:00+01:00","dbNazev":"sveatlo1","id":"4","licenseGroup":"null","nazev":"Sveatlo1","show":"true","stavEnum":"ESTABLISHED","watchingChanges":"false"}]

In the first case, when there is just one item the hometables_one function runs without any problems, but adding another item results in error [Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number or [Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac . 在第一种情况下,当只有一个项目时, hometables_one函数运行没有任何问题,但添加另一项导致错误[Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number[Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac Another thing is that when I run the code without multiprocessing, ie content of hometable_one function is in the for loop in hometables function, it runs without any problems. 另一件事是,当我在没有多处理的情况下运行代码时,即hometable_one函数的内容在hometables函数的for循环中,它运行没有任何问题。 Why am I getting these errors? 为什么我会收到这些错误? Could anybody help me please? 请问有人帮帮我吗?

Thanks for any answer 谢谢你的回答

I have experienced similar problems. 我遇到过类似的问题。 I think this error is the result of multiple processes trying to access the same SSL connection. 我认为此错误是多个进程尝试访问同一SSL连接的结果。 What you can try is to introduce a random delay for each process before they fire off the request: 您可以尝试的是在每个进程触发请求之前引入随机延迟:

time.sleep(random.randrange(10))
r = s.get("%s/c.json" % hostname, params=payload, verify=False)

暂无
暂无

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

相关问题 python 请求:(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1123)')) - python requests: (SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')) SSLError:[Errno 1] _ssl.c:510:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 - SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 身份验证失败:[Errno 1] _ssl.c:510:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 - Authentication failed: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed <urlopen error [Errno 1] _ssl.c:510: error:14077417:SSL - <urlopen error [Errno 1] _ssl.c:510: error:14077417:SSL python elasticsearch elasticsearch.exceptions.SSLError: ConnectionError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)) - python elasticsearch elasticsearch.exceptions.SSLError: ConnectionError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)) _ssl.c:351:错误:140B0009:SSL例程:SSL_CTX_use_PrivateKey_file:PEM库 - _ssl.c:351: error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib Flask-Mail [SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1123) - Flask-Mail [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123) 如何修复 ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1056)? - How to fix ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)? Python SSLError:客户端错误(EOF发生违反协议),服务器端错误(SSL3_GET_RECORD:错误的版本号) - Python SSLError: Client-side-error(EOF occurred in violation of protocol), Server-side-error(SSL3_GET_RECORD:wrong version number) Python 请求 requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF 发生违反协议 - Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM