ECONNRESET error after upgrading packages

Summary:

Hi Team,

Hope you are well.

I am having an issue with OpenSSL which I didnt experience before.

I am running a Python script that extracts data from a DMP's API (https://www.lotame.com/). The script has been working for a month now and I was able to extract data properly for over a month now.

## Expected Result
`affinities_table begun, current row length = 39
id 158260 added, current row length = 69
id 153226 added, current row length = 194
id 153237 added, current row length = 446
id 153235 added, current row length = 879
id 159852 added, current row length = 1696
id 153232 added, current row length = 1969
id 153225 added, current row length = 2483
id 153230 added, current row length = 2722
id 151975 added, current row length = 3015
id 153701 added, current row length = 3415
id 153697 added, current row length = 3781
id 151977 added, current row length = 4134
id 153700 added, current row length = 4418
id 153698 added, current row length = 5068
id 153699 added, current row length = 5467
id 153705 added, current row length = 7487
id 161726 added, current row length = 7508
id 172973 added, current row length = 8004
id 153993 added, current row length = 8029
id 153994 added, current row length = 8084
id 153996 added, current row length = 8215
id 153995 added, current row length = 8337
id 168763 added, current row length = 8628
id 168762 added, current row length = 8919
id 153236 added, current row length = 9044
id 151980 added, current row length = 9279
id 153228 added, current row length = 9562
id 153229 added, current row length = 9745
id 179586 added, current row length = 9804
id 196979 added, current row length = 9829
id 175403 added, current row length = 10481
id 190349 added, current row length = 11116
id 192283 added, current row length = 12044
id 192282 added, current row length = 12395
id 197643 added, current row length = 13304
id 197645 added, current row length = 14860
id 197646 added, current row length = 14861
id 197647 added, current row length = 16526
id 197649 added, current row length = 18267
id 197651 added, current row length = 20337
id 197653 added, current row length = 22180
id 197655 added, current row length = 24275
`





## Actual Result
But when I upgrade requests, pyopenssl, and other packagesI received below error:
```
affinities_table begun, current row length = 39
Traceback (most recent call last):
    tbl = audience_affinities(config_filepath, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 457, in audience_affinities
    aud_affinities = single_audience_affinities(config_filepath, i, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 389, in single_audience_affinities
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: SysCallError(104, 'ECONNRESET')",)
Traceback (most recent call last):
KeyError: 'location'
affinities_table begun, current row length = 39
Running audaffinities job
affinities_table begun, current row length = 39
Traceback (most recent call last):
    tbl = audience_affinities(config_filepath, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 460, in audience_affinities
    aud_affinities = single_audience_affinities(config_filepath, i, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 392, in single_audience_affinities
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)
affinities_table begun, current row length = 39
```
Now, I also ran the command to update all of my python packages.

## Reproduction Steps

```python
import requests

```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.0"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.13"
  },
  "platform": {
    "release": "2.6.32-431.29.2.el6.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010006f",
    "version": "17.2.0"
  },
  "requests": {
    "version": "2.14.2"
  },
  "system_ssl": {
    "version": "100020cf"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}

```
Also, more information:

- Python version 2.7.13
- Operating system: CentOS release 6.5 (final)

Let me know if you need more information.

Cheers,

Sugi

Thanks for this issue! Did you also upgrade `cryptography`? Can you try downgrading `cryptography` to version 1.9 and see if the problem reproduces?

hahahha, happy to be of help.

Yes, I did as I also upgrade all of my Python packages.

Will try to run this with downgraded cryptography version 1.9 and get back to you on this.


Hi @Lukasa,

I tried running it with cryptography version 1.9 and I got a different error:

```
Traceback (most recent call last):
    tbl = audience_sites(config_filepath, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 237, in audience_sites
    aud_sites = single_audience_sites(config_filepath, i, date_today)
  File "/home/slauw/Lotame_test/lotame_api_optimized.py", line 204, in single_audience_sites
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))
Running audaffinities job
affinities_table begun, current row length = 39
```


Interesting. That error is a misbehaviour in the server, not correctly terminating a chunk-encoded body. Have you encountered this error before?

@Lukasa Yes, i did when I was testing my script to extract data from the website's API.

But I have been running this script for over a month without any issue until I upgraded all of my Python packages....

Hrm, interesting. Can you print the headers of each response and show me the ones for the response that triggers that exception?

Hi @Lukasa,

Hm, this is weird. 

I was expecting an error happening but it seems like its working properly this time. In saying that though, there is still chance that it will return error from time to time.

Let me do more testing on this and I will grab the response headers when it returns an error.

No further information provided to help reproduce. Closing until that is provided.