title: Python requests ssl [Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
body: <p>I'm creating a python app, using requests module. I recently add multiprocessing to speed it up a bit, but I started to get some strange errors like <code>[Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number</code> or <code>[Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac</code>.
  The code looks like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>In this part</p>
  
  <pre><code>    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)
  </code></pre>
  
  <p>I get a JSON request with all companies currently in system and then I run the hometables_one function for each of them. The final <code>data</code> may look like this:</p>
  
  <pre><code>[{"createDt":"2014-01-28T00:00:00+01:00","dbNazev":"sveatlo","id":"4","licenseGroup":"null","nazev":"Sveatlo","show":"true","stavEnum":"ESTABLISHED","watchingChanges":"false"}]
  </code></pre>
  
  <p>or like this:</p>
  
  <pre><code>[{"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"}]
  </code></pre>
  
  <p>In the first case, when there is just one item the <code>hometables_one</code> function runs without any problems, but adding another item results in error <code>[Errno 1] _ssl.c:1428: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number</code> or <code>[Errno 1] _ssl.c:1428: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac</code>. Another thing is that when I run the code without multiprocessing, i.e. content of hometable_one function is in the for loop in hometables function, it runs without any problems.
  Why am I getting these errors? Could anybody help me please?</p>
  
  <p>Thanks for any answer</p>