Raibek/requests-github-issues huggingface dataset:
AttributeError: module 'requests.packages' has no attribute 'urllib3'

This [commit](https://github.com/requests/requests/commit/588e8f7f640f774e71d61b53ccb34d310172e0ad) seems to have broken requests.packages.

## Expected Result

requests.packages.urllib3 to be the urllib3 package

## Actual Result

AttributeError: module 'requests.packages' has no attribute 'urllib3'

## Reproduction Steps

```python
import requests
requests.packages.urllib3
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.3"
  },
  "cryptography": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.1"
  },
  "platform": {
    "release": "4.11.2-1-ARCH",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.17.1"
  },
  "system_ssl": {
    "version": "1010006f"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": false
}
```

Interesting, I am unable to reproduce locally

nevermind!

I'm able to reproduce this locally. It looks like this may be the product of removing the actual `import` statements.

fix released in 2.17.2!

Thanks for the speedy resolution!

Thanks for the speedy release, but it does not work for us.

On OS-X, it fails (see the end of this Travis log: https://travis-ci.org/zhmcclient/python-zhmcclient/jobs/237306514

Update: I restarted that run. Maybe it interfered with the release. Let's see how it works.

Update: 2.17.2 fails with the same symptom as in 2.17.1:
```
Successfully installed certifi-2017.4.17 chardet-3.0.3 click-6.7 click-repl-0.1.2 click-spinner-0.1.7 decorator-4.0.11 idna-2.5 pbr-3.0.1 progressbar2-3.20.2 prompt-toolkit-1.0.14 python-utils-2.1.0 requests-2.17.2 stomp.py-4.1.17 tabulate-0.7.7 urllib3-1.21.1 wcwidth-0.1.7 zhmcclient-0.13.1.dev39
python -c "import zhmcclient; print('Import: ok')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "zhmcclient/__init__.py", line 30, in <module>
    from ._session import *       # noqa: F401
  File "zhmcclient/_session.py", line 29, in <module>
    from requests.packages import urllib3
ImportError: cannot import name urllib3
```

It seems like although the latest version is now 2.17.2 the release doesn't actually contain the fix.

@ryanpineo 2.17.3

All good now, thanks!

I can confirm that requests 2.17.3 worked fine again on Py 2.7 on Ubuntu. I'll update our requirements.txt file to exclude requests 2.17.1 and 2.17.2, and re-run all other environments and if you don't hear from me, they were fine.

Again, thanks much for the speedy fix!!

\o/
submodules of requests.packages.urllib3 are not equal to urllib3's

See title. Caused by the unbundling and related to e.g. #4072 

## Reproduction Steps

```python
import requests.packages.urllib3
import urllib3

from requests.packages.urllib3.connectionpool import HTTPConnection as old
from urllib3.connectionpool import HTTPConnection as new
assert old is new
```

The assertion should not fail, but does on my machine

## System Information

```
{
  "chardet": {
    "version": "3.0.3"
  },
  "cryptography": {
    "version": "1.8.1"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.1"
  },
  "platform": {
    "release": "4.10.13-1-ARCH",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "100020bf",
    "version": "16.2.0"
  },
  "requests": {
    "version": "2.17.0"
  },
  "system_ssl": {
    "version": "1010005f"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": true
}

```

Thank you for bringing such a reproducible case. I'll see what I can do. 

I have a clue what might help, let me see.

<3
Connection pool is full, discarding connection: localhost in 2.17.0

Summary.

After upgrading to 2.17.0 (from 2.14.2) I got an immediate failure on all apps using the requests lib.

Given the fact that no one else has seen this, I expect it's an incompatibility between other libs. 
Filing here first to track.

## Expected Result

No exception in normal use case.

What you expected.

No exception in normal use case.

## Actual Result

```
u'25177330-cf2a-3943-af3b-86582902a2cc', u'f296a708-e02c-393, resp:None, <type 'exceptions.ValueError'> Timeout value connect was Timeout(connect=None, read=None, total=None), but it must be an int, float or None.
Traceback (most recent call last):
  File "/opt/nim/ur-api/mlutil/sdk/nimsdk.py", line 154, in _GET
    params=arguments
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 526, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 623, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 587, in urlopen
    timeout_obj = self._get_timeout(timeout)
  File "/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 302, in _get_timeout
    return Timeout.from_float(timeout)
  File "/usr/local/lib/python2.7/dist-packages/urllib3/util/timeout.py", line 154, in from_float
    return Timeout(read=timeout, connect=timeout)
  File "/usr/local/lib/python2.7/dist-packages/urllib3/util/timeout.py", line 94, in __init__
    self._connect = self._validate_timeout(connect, 'connect')
  File "/usr/local/lib/python2.7/dist-packages/urllib3/util/timeout.py", line 127, in _validate_timeout
    "int, float or None." % (name, value))
ValueError: Timeout value connect was Timeout(connect=None, read=None, total=None), but it must be an int, float or None.
```

What happened instead.

See exception above

## Reproduction Steps

Have not tried to isolate or narrow focus. 

## System Information

    $ python -m requests.help

```
ubuntu@ip-10-200-17-89:~$ python --version
Python 2.7.12
ubuntu@ip-10-200-17-89:~$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
```

This command is only available on Requests v2.16.4 and greater. Otherwise,
please provide some basic information about your system (Python version,
operating system, &c).

Thanks for taking the time to open this ticket, @bedge. I've got a feeling this is related to the unvendoring of Requests' dependencies. It looks like this *should* be solved in 2.17.1. Would you mind upgrading before we continue debugging here?

Confirmed fixed in:
```
requests==2.17.3
```
Thanks for the rapid response.

\o/
move functionlocal imports in utils.py and models.py to global scope

This avoids runtime warnings when using the `requests` module for the first time when it is no longer in `sys.modules`. 

```
[...]\Lib\site-packages\requests\utils.py:164: RuntimeWarning: Parent module 'requests' not found while handling absolute import
  from netrc import netrc, NetrcParseError
[...]\Lib\site-packages\requests\utils.py:49: RuntimeWarning: Parent module 'requests' not found while handling absolute import
  import _winreg as winreg
```

Seeing this warning is very common for me, since I develop Python plugins for an application that embeds Python. To ensure that no dependencies between plugins are conflicting, every plugin develiers its own dependencies and makes sure they leave no trace in `sys.modules` and `sys.path`.

Hrm, I'm pretty nervous about this. It's hard for us to avoid regressing this behaviour and it's extremely likely that we'd add it somewhere else. Is it not more advisable to silence the warning?

While that is possible, eg. by wrapping the requests API, the [`warnings` "Temporarily Suppressing Warnings"][0] documentation states that the behaviour is undefined in multithreaded applications.

  [0]: https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings

Suppressing all warnings, always, is definitely not an option.

```python
def requests_get(*args, **kwargs):
  with warnings.catch_warnings():  # UB in multithreaded applications
    warnings.simplefilter('ignore')
    return requests.get(*args, **kwargs)
```


I'm going to close this.
test

changed humans to human

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=h1) Report
> Merging [#4091](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/78349914c818db5f904f630e3614e488260772ef?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4091/graphs/tree.svg?width=650&src=pr&token=mZGswIiXLa&height=150)](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #4091   +/-   ##
=======================================
  Coverage   87.45%   87.45%           
=======================================
  Files          18       18           
  Lines        2025     2025           
=======================================
  Hits         1771     1771           
  Misses        254      254
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=footer). Last update [7834991...4e56506](https://codecov.io/gh/kennethreitz/requests/pull/4091?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
test 4


# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=h1) Report
> Merging [#4089](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/78349914c818db5f904f630e3614e488260772ef?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4089/graphs/tree.svg?src=pr&width=650&token=mZGswIiXLa&height=150)](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #4089   +/-   ##
=======================================
  Coverage   87.45%   87.45%           
=======================================
  Files          18       18           
  Lines        2025     2025           
=======================================
  Hits         1771     1771           
  Misses        254      254
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=footer). Last update [7834991...8ddba46](https://codecov.io/gh/kennethreitz/requests/pull/4089?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
try this travis file


# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=h1) Report
> Merging [#4086](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/303eca03f31741571fe2025d792ca3db28687078?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4086/graphs/tree.svg?src=pr&width=650&token=mZGswIiXLa&height=150)](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #4086   +/-   ##
=======================================
  Coverage   87.45%   87.45%           
=======================================
  Files          18       18           
  Lines        2025     2025           
=======================================
  Hits         1771     1771           
  Misses        254      254
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=footer). Last update [303eca0...2ccecf6](https://codecov.io/gh/kennethreitz/requests/pull/4086?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
AttributeError using socks5 support [socks]

Using requests with a socks5 proxy fails on:
AttributeError: 'super' object has no attribute 'settimeout'

## Reproduction Steps
`pip install requests[socks]==2.14.2`
(this installs PySocks v1.6.7)

run a socks proxy on port 9050. I use Tor for that matter.

Simplified code I use is:
```python
import requests
proxies={'http': 'socks5://127.0.0.1:9050'}
url = 'http://www.whatismyip.org/'
requests.get(url, proxies=proxies)
```


## System Information

```
Windows 7 (x64): 6.1.7601
Python 2.7.12 64bit
```

## Full Traceback
  File "c:\Python27\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "c:\Python27\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "c:\Python27\lib\site-packages\requests\sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\Python27\lib\site-packages\requests\sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "c:\Python27\lib\site-packages\requests\adapters.py", line 438, in send
    timeout=timeout
  File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "c:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "c:\python27\Lib\httplib.py", line 1057,in request
    self._send_request(method, url, body, headers)
  File "c:\python27\Lib\httplib.py", line 1097, in _send_request
    self.endheaders(body)
  File "c:\python27\Lib\httplib.py",line 1053, in endheaders
    self._send_output(message_body)
  File "c:\python27\Lib\httplib.py", line 897, in _send_output
    self.send(msg)
  File "c:\python27\Lib\httplib.py", line 859,in send
    self.connect()
  File "c:\Python27\lib\site-packages\requests\packages\urllib3\connection.py", line 166, in connect
    conn = self._new_conn()
  File "c:\Python27\lib\site-packages\requests\packages\urllib3\contrib\socks.py", line 88, in _new_conn
    **extra_kw
  File "c:\Python27\lib\site-packages\socks.py", line 229, in create_connection
    sock.connect((remote_host, remote_port))
  File "c:\Python27\lib\site-packages\socks.py", line 96, in wrapper
    return function(*args, **kwargs)
  File "c:\Python27\lib\site-packages\socks.py", line 781, in connect
    super(socksocket, self).settimeout(self._timeout)
AttributeError: 'super' object has no attribute 'settimeout'

## Extras
I want to suggest the closest issue I have found, that is on **gevent**:
https://github.com/gevent/gevent/issues/937

Replacing all occurences of (in socks.py):
`super(socksocket, self).settimeout`
with:
`self.settimeout`
solves the issue, but I don't know if there are any other side effects


This error comes from PySocks, not from Requests: you'll need to open your issue on [this repository](https://github.com/anorov/pysocks).
Jenkins (tesT)


# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=h1) Report
> Merging [#4082](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/03944f4cd62fb906cb20eebda86b150358923564?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4082/graphs/tree.svg?width=650&height=150&token=mZGswIiXLa&src=pr)](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #4082   +/-   ##
=======================================
  Coverage   87.65%   87.65%           
=======================================
  Files          18       18           
  Lines        2025     2025           
=======================================
  Hits         1775     1775           
  Misses        250      250
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=footer). Last update [03944f4...3e5498e](https://codecov.io/gh/kennethreitz/requests/pull/4082?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
TEST Update README.rst


# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=h1) Report
> Merging [#4081](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/03944f4cd62fb906cb20eebda86b150358923564?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4081/graphs/tree.svg?width=650&height=150&src=pr&token=mZGswIiXLa)](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #4081   +/-   ##
=======================================
  Coverage   86.07%   86.07%           
=======================================
  Files          18       18           
  Lines        2025     2025           
=======================================
  Hits         1743     1743           
  Misses        282      282
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=footer). Last update [03944f4...6cf0962](https://codecov.io/gh/kennethreitz/requests/pull/4081?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
test

Summary.

## Expected Result

What you expected.

## Actual Result

What happened instead.

## Reproduction Steps

```python
import requests

```

### System Information

    $ python -m requests.help

```
{
  "chardet": "3.0.3",
  "cryptography": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.0"
  },
  "platform": {
    "release": "16.6.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.16.4"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": "1.21.1",
  "using_pyopenssl": false
}
```

This command is only available on Requests v2.16.4 and greater. Otherwise,
please provide some basic information about your system (Python version,
operating system, &c).

Any reason for the inconsistency with the `urllib3` and `chardet` keys not having `version` sub-keys?

@SethMichaelLarson looks like those two were added after the other original definitions. Perhaps `urllib3_info = {'version': urllib3.__version__}` [here](https://github.com/kennethreitz/requests/blob/7ce5ca853db84601fe61209428085bac2b79309b/requests/help.py#L72-L73) would be more consistent, @kennethreitz?

Also noticed we're not saying anything about OS information/version here? Might be worthwhile.

@SethMichaelLarson I believe that's what the `platform` key is representing. I'm not sure if there's more specific information we can get out of the `platform` package. I haven't looked too hard though.

@nateprewitt Disregard me, just didn't see that field.

ah, good catch

updated :)
Restore "packages" namespace for backwards compatibility 


shipped. 

I'm afraid this doesn't resolve the problem with many libraries, such as the official Dropbox and Keen clients, which do

`from requests.packages.urllib3.poolmanager import PoolManager`

This results in the following error:

`ModuleNotFoundError: No module named 'requests.packages.urllib3'; 'requests.packages' is not a package`


I'm trying to find a solution for them too @raicheff. I'm open to suggestions. 

Currently, code that was written to import against the `requests.packages` namespace previously will have to import code that rests at this module-level now.

For example:

    from requests.packages.urllib3.poolmanager import PoolManager

Will need to be re-written to be:

    from requests.packages import urllib3
    urllib3.poolmanager.PoolManager

Or, even better:

    from urllib3.poolmanager import PoolManager

If we really want backwards compatibility, we may have to stub out the whole library as an empty imported package. I'm willing to do that, if needed. 

solution found!

https://github.com/kennethreitz/requests/commit/c952e9e4e07ebaf579aaf8924ff6f7c61710c8c8

@raicheff care to test against master and see if that solves the issue for you, for the next release?

@kennethreitz Yes, just tested it and it works!

\o/ 

will cut a release shortly

Thanks Kenneth, that's awesome!

This solution is ugly is hell, but I guess it will do the job for now. I would suggest you add a deprecation warning on import of these modules (similar to how Flask does it with the `ext` package), and remove the shimmed packages in the next major release.

I came up with a much better solution. 

https://github.com/kennethreitz/requests/commit/28666e5d3ae04fede9a9078aba937b0ce6380adc

going to cut a release

shipped 2.16.2!

Tested – works!

With 2.16.2, coala's core tests are down to only one error, in an emulated read timeout test.
https://circleci.com/gh/jayvdb/coala/296
We still have a few other issues which have strangely popped up, and probably some version conflicts for `chardet`.  Still investigating.

@jayvdb keep us up to date!

@kennethreitz , I haven't found the cause of https://github.com/coala/coala/issues/4282 (and it is 3am so I'm off) , but the workaround was simple : https://github.com/coala/coala/pull/4283


excellent @jayvdb!

@kennethreitz , my workaround shows there is a significant breaking change somewhere.
"Packages" module is missing in Requests 2.16.0

Description
We are using requests package for our application development and the framework picks up latest version of requests whenever it builds.Today we noticed that our app broken due to new version of Requests 2.16.0.The "Packages" module is completely missing and it leads to our delivery blocking,Could you please check and let us know if we can expect any quick fix for this issue?

Working version:
2.14.2 and 2.15.1

This is a duplicate of #4069, please check open issues before raising bug reports. This goes double for emailing maintainers directly: it would have taken you 5 seconds to see your issue on the issue tracker. 

Sorry for the duplicate

2.16.1 released, which fixes this!

Note: code that was written to import against the requests.packages namespace previously will have to import code that rests at this module-level now.

For example:

    from requests.packages.urllib3.poolmanager import PoolManager

Will need to be re-written to be:

    from requests.packages import urllib3
    urllib3.poolmanager.PoolManager

Or, even better:

    from urllib3.poolmanager import PoolManager

Requests v2.16.2 is now out, which makes the above code no longer necessary.
ImportError: No module named 'requests.packages' for version 2.16.0

```
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests.packages.urllib3.poolmanager import PoolManager
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'requests.packages'
```
The following import statement used to work for the older version `2.14.2` but fails for the latest version `2.16.0`

This is a duplicate of #4069: please check open issues before reporting bugs. 😉

My bad.

Note: code that was written to import against the requests.packages namespace previously will have to import code that rests at this module-level now.

For example:

    from requests.packages.urllib3.poolmanager import PoolManager

Will need to be re-written to be:

    from requests.packages import urllib3
    urllib3.poolmanager.PoolManager

Or, even better:

    from urllib3.poolmanager import PoolManager

Requests v2.16.2 is now out, which makes the above code no longer necessary.
Error on importing Session object

Hi guys
I'm using requests (2.16.0) and I'm seeing an error which wasn't here before : 

```
Python 3.5.2 (default, Jul 17 2016, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> urllib3.__version__
'1.16'
>>> from requests import Session
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jenkins/env/lib/python3.5/site-packages/requests/__init__.py", line 49, in <module>
    major, minor, patch = urllib3.__version__.split('.')[:3]
ValueError: not enough values to unpack (expected 3, got 2)
>>> 
```

Yup, this looks like another error introduced by #4067, which appears to assume urllib3 uses three part version numbers (it does not always do that). You can resolve this by typing `pip install -U urllib3`, though that may break something else in your environment. 

Please watch #4069, as we may well revert the change in 2.16.

Incidentally @kennethreitz, this is why I didnt want to do this before pip gets a dependency solver: a whole bunch of people who could use Requests before now cannot. 

this should now be fixed to provide a proper error on the master branch
2.16.0 Release Breaking Changes if you relied on Vendored packages

Hey so the 2.16.0 release broke all of the vendored things I am assuming. I have [issued](https://github.com/tomchristie/apistar/pull/189) two [PRs](https://github.com/encode/django-rest-framework/pull/5185) to two frameworks I use that rely on the vendored packages in requests.

The `changelog` was a bit obscure about this
> 2.16.0
> Unvendor ALL the things!

Something like `BREAKING CHANGE: Vendor packages have been removed, if you relied on these you will need to modify your code` would be nice in a 2.16.1 changelog update maybe?

I realize that it can be said these vendored packages are internal and should not be relied on but at least these packages had a use case for using requests and some of the underlying libs and used the vendor packages to ensure everything worked as expected with requests.

Anyone who was relying on these will have their code break upon upgrade, so perhaps a bigger version bump would have been welcome, but at least this can be a warning to people coming here wondering why stuff broke. My solution was a `compat.py` that conditionally imported `urllib3` (works the same for other vendored packages), see my PRs for that fix.

Yeah, I don't know why @kennethreitz released that: it was pretty obviously going to break a lot of software. Not sure what I can say here: this is ultimately @kennethreitz's software and he can do what he wants, and I'm not going to revert his changes. But there was simply no reason that unvendoring needed to be shipped prior to v3, so I really hope @kennethreitz reverts and pushes a release containing that revert.

Related: #4073

@audiolion can you provide a sample of the code you were importing to utilize the internal packaged code? I'd like to test that I'm brining back the namespace properly. 

2.16.1 released, which restores the `packages` namespace. Sorry for the hiccup!

@kennethreitz hey! its the two PRs that I have in my first comment, you can check either for how I did it, worked for both of those libs

v2.16.2 of requests fixes the backwards incompatibility completely :)

Sorry to ruin your Saturday! thanks for all you do

No, sorry for ruining yours! :)

This still does not work with 2.16.2.
```python
>>> import requests
>>> requests.packages
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'requests' has no attribute 'packages'
```

Was trying out the apistar project today and ran into this issue since it uses that way of accessing the module.

ah, I can fix that. 

@thrawny v2.16.3 released, which restores this. 

Thanks for the report!
Deps (work in progress)

This pull request works on removing all vendored dependencies from Requests. 

Targeting v2.16.0. 

✨🍰✨

all tests passing (on python 3 at least!)

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=h1) Report
> Merging [#4067](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/282b01a7c9feae30feccbd54e33afcc06197df62?src=pr&el=desc) will **increase** coverage by `0.09%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4067/graphs/tree.svg?src=pr&token=mZGswIiXLa&width=650&height=150)](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #4067      +/-   ##
==========================================
+ Coverage    88.1%   88.19%   +0.09%     
==========================================
  Files          16       16              
  Lines        1958     1949       -9     
==========================================
- Hits         1725     1719       -6     
+ Misses        233      230       -3
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/sessions.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvc2Vzc2lvbnMucHk=) | `92.7% <100%> (ø)` | :arrow_up: |
| [requests/exceptions.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvZXhjZXB0aW9ucy5weQ==) | `100% <100%> (ø)` | |
| [requests/adapters.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvYWRhcHRlcnMucHk=) | `92.92% <100%> (ø)` | :arrow_up: |
| [requests/models.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvbW9kZWxzLnB5) | `93.63% <100%> (+0.61%)` | :arrow_up: |
| [requests/compat.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvY29tcGF0LnB5) | `100% <100%> (ø)` | |
| [requests/certs.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-cmVxdWVzdHMvY2VydHMucHk=) | `75% <100%> (-13.89%)` | :arrow_down: |
| [tests/testserver/\_\_init\_\_.py](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=tree#diff-dGVzdHMvdGVzdHNlcnZlci9fX2luaXRfXy5weQ==) | `92.59% <0%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=footer). Last update [282b01a...d271341](https://codecov.io/gh/kennethreitz/requests/pull/4067?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Remembering now why I hated Travis CI when it first launched. 

YOLO!

👍
API improvements

- `Response.next`

Related: #4065.

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=h1) Report
> Merging [#4066](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/60041f51693fd6107ad91337222aa3dc125720ac?src=pr&el=desc) will **decrease** coverage by `2.83%`.
> The diff coverage is `82.35%`.

[![Impacted file tree graph](https://codecov.io/gh/kennethreitz/requests/pull/4066/graphs/tree.svg?token=mZGswIiXLa&src=pr&height=150&width=650)](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #4066      +/-   ##
==========================================
- Coverage   89.78%   86.94%   -2.84%     
==========================================
  Files          16       16              
  Lines        1948     1961      +13     
==========================================
- Hits         1749     1705      -44     
- Misses        199      256      +57
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/sessions.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvc2Vzc2lvbnMucHk=) | `92.36% <100%> (-1.59%)` | :arrow_down: |
| [requests/models.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvbW9kZWxzLnB5) | `92.17% <50%> (-1.26%)` | :arrow_down: |
| [requests/packages/chardet/compat.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvcGFja2FnZXMvY2hhcmRldC9jb21wYXQucHk=) | `64.86% <0%> (-35.14%)` | :arrow_down: |
| [requests/utils.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvdXRpbHMucHk=) | `79.25% <0%> (-7%)` | :arrow_down: |
| [requests/\_internal\_utils.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvX2ludGVybmFsX3V0aWxzLnB5) | `93.75% <0%> (-6.25%)` | :arrow_down: |
| [requests/cookies.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvY29va2llcy5weQ==) | `76.27% <0%> (-0.85%)` | :arrow_down: |
| [requests/auth.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvYXV0aC5weQ==) | `85.8% <0%> (-0.62%)` | :arrow_down: |
| [requests/adapters.py](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=tree#diff-cmVxdWVzdHMvYWRhcHRlcnMucHk=) | `92.45% <0%> (-0.48%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=footer). Last update [60041f5...c3367d1](https://codecov.io/gh/kennethreitz/requests/pull/4066?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
Requests library raises ConnectionError if web-server returns error but only when uploading large file

Version: requests (2.12.4)

I'm running a webserver based on the Bottle framework. This framework exposes an endpoint where you can upload a file. Sometimes, if the disk is full, the webserver is supposed to return a code 429 without reading the file. For some reason, when I'm uploading a file, if the server tries to return a 429 status code the following exception is raised:

```python
 File "../hooks.py", line 325, in post_video_content
    response = requests.post(url, data=fh)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 473, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(32, 'Broken pipe'))
```
But if try the exact same post but instead of posting a file I simply post some small amount of data, I actually get a response object back from the request and I can inspect the status code.

To reproduce:

webserver.py
```python
from bottle import Bottle, route, run, request, response, get, post, put, abort

@post('/content')
@authenticate
def content():
    response.status = 429
    return "failed to write incoming movie to temp file (space might be full temporarily)"

run(host="127.0.0.1", port=8080, debug=True)
```

send_request.py

```python
import requests

# this works and prints the status code
ret = requests.post("127.0.0.1:8080/content", data="sdfsdfsdfsdf")
print ret.status_code

# this part will throw an exception
try:
    with open("~/some_large_video_file.mp4", 'rb') as fh:
        ret = requests.post('127.0.0.1:8080/content', data=fh)
except:
    print traceback.format_exc()
```

I've found out that it depends on the amount of data. If you try and post something like 10KB of data we get the 429 return code. So it looks like the magic filesize is somewhere between 104K and 117K. If I try the former it works as intended, I get the response from the request and can access the status code. If I try the former I get the exception raised.

Unfortunately, this is a known problem with Requests that boils down to our use of httplib. We can't do much about it right now, but we're planning to abandon httplib sometime this year, so hopefully we'll resolve that then. 

thanks for letting me know, I'll have to figure out some workaround.
readthedocs is broken

ugh https://readthedocs.org/projects/requests/builds/5472443/

very unclear what's going on from the error message. @ericholscher?

Does it happen locally?

I seem to have it reproducing locally, so I'm guessing it's a bug in something recent on your side. 

Locally I see your config version being set as `ipdb> version
<module 'requests.__version__' from '/Users/eric/checkouts/requests/requests/__version__.pyc'>` which seems...wrong :)

Looks like this is a byproduct of #4059. Something is getting confused about requests.__version__ the module vs requests.__version__ the attr. The import statement in init may need to be more explicit, or the module name needs to change.

gah, sorry @ericholscher. I should have checked that before pinging you!
"params" arg of requests.get does not properly encode json

I have an API endpoint that handles json. This request returns a 400 error 
```
requests.get(url, params={"json":json.dumps(myDict)}
``` 
while this works fine 
```
requests.post(url,json=myDict)
```
Is there no proper way to pass json in a GET request?

This is entirely up to your API endpoint. If the endpoint doesn't want JSON in the request URL, then it will error out: if it does, then it won't. You need to read your endpoint documentation or observe other requests to see how they send the data.

No, the API can handle JSON in the request URL. It's just that when I pass json as a value a-la `params={key:value}` in the GET request, the json gets formatted improperly. The url it returns places a `+` character after every `:` in the json. 

That's not improper, that's the result of `json.dumps`:

```python
>>> json.dumps({'test': 'name'})
'{"test": "name"}'
```

If that's not the way you want your data to look, you need to change the data. We're going to send exactly what you ask us to. :smile:

Ah, yes! So I guess by specifying `separators=(',' , ':')` the json.dumps() call I can get rid of the `+`'s. Thanks!
move setup.py to use a __version__.py

better pattern. death to regex. 

Would be nice to keep `__version__` exposed at the package level so that `requests.__version__` is still a thing.

Absolutely!

Only reason I note that is because I know that `pipenv` does not expose `.__version__` at the package level instead opting for `pipenv.__version__.__version__`.

@SethMichaelLarson can you open an issue about that?

Addressed in #4059
remove 301 redirect cache

it's not thread-safe, it's problematic, and it's just not the best of ideas. 

-----------

I'm assigning this to myself, but anyone can feel free to take this on if they're in the mood!

Just comment here when you start working on it, if so! 

I thought we'd already removed this for 3.0?

I think @kennethreitz has OK'd removing it for 2.x too.

Yeah, I'm personally fine with that. 

I opened a PR for this issue. (#4100)

✨🍰✨

@kennethreitz 

How is it not threadsafe?

This `RecentlyUsedContainer` seems to be threadsafe. 
 The implementation uses `threading.RLock` [see source](https://github.com/urllib3/urllib3/blob/master/src/urllib3/_collections.py)

Even if the redirect cache was just a Python dictionary it would be threadsafe... right?

https://docs.python.org/3/glossary.html#term-global-interpreter-lock

> The mechanism used by the CPython interpreter to assure that only one thread executes Python bytecode at a time. This simplifies the CPython implementation by making the object model (including critical built-in types such as dict) implicitly safe against concurrent access.
Easter Egg

I'd like to embed an easter egg within requests — something very simple, perhaps just a single dunder variable that says "Kenneth was here". 

OR! 

```
>>> requests.__cake__
✨ 🍰 ✨
```
yes, i love this. 

Any objections will be heard, and likely ignored, but open to thougts if anyone feels strongly against it.

Done!

Did on my iPad, trusting CI to report if there are any failures caused by this one-line change. Keeping an eye out, as I don't have a dev environment on me at the moment. 

@Lukasa sorry! :sparkles: :cake: :sparkles:

:wink: No worries.
Trouble with a specific request

Hi,
I have a trouble with my python code.
When i do this cUrl, it work : 
`curl -i -XPOST 'http://51.255.80.74:8086/write?db=testdb' --data-binary 'lps0,host=serverlama,region=us-west value=0.65'`
My value is added in to my database.
I want to do the same in python with this script:

````
import requests
import xml.etree.ElementTree as ET

###
interestingData = ['lps0','wuc0']

###INFLUXDB INFOS
databaseName = 'testdb'
urlPostData = 'http://51.255.80.74:8086/write?db='+databaseName

urlGetData = 'http://192.168.168.110/admin/status.xml'
source = requests.get(urlGetData, stream=True)

tree = ET.parse(source.raw)
root = tree.getroot()

for child in root:
        if child.tag in interestingData:
                data = ''+child.tag+',host=serverlama,region=us-west value='+child.text
                response = requests.post(urlPostData, data=data, headers={'Content-Type': 'application/octet-stream'})
````

But i got this error :

````
Traceback (most recent call last):


 File "script3.py", line 27, in <module>
    response = requests.post(urlPostData, data=data, headers={'Content-Type': 'application/octet-stream'})
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 94, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 49, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 457, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 569, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 407, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
````

My code seems good to me, i tried a lot of solutions but none works :(
If anyone has an idea, it would be great 

Let's get discorse setup, for questions like this. 

Your GET is failing. Why are you trying that GET?

My get is working, and i make that get for dowload the xml content of the page.
The problem is on the requests.post().

So all I can tell you then is that the server is refusing our connection attempt.

Yes but i had already this information :)
My server doesn't refuse the connection attempt when i make a cUrl, why the connection would be refused with a request in python ?

Can we confirm you're not getting redirected? That is, can you set `allow_redirects=False`?

I'm so sorry, i was testing my curl on my PC, not in my container. 
Thanks for your help ! :)


> Let's get discorse setup, for questions like this.

Why can't we simply use StackOverflow for that? That's something we don't need to host @kennethreitz 

@sigmavirus24 discourse will give us a free hosted account. I think it'll give our users the opportunity to talk to eachother and self-serve issues potentially.
Prevent reading whole file when using the files= argument

I am trying to send a very large file (100Gb) using a POST request, with a call that looks like:

```
 r = requests.post(url, data={'filename': filename}, files={'file': f})
```

but the issue is that internally, requests tries to read the whole file before sending:

```
  File "upload.py", line 19, in <module>
    files=files)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/sessions.py", line 349, in request
    prep = self.prepare_request(req)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/sessions.py", line 287, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/models.py", line 290, in prepare
    self.prepare_body(data, files)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/models.py", line 427, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "/home/robitaille/anaconda/lib/python2.7/site-packages/requests/models.py", line 140, in _encode_files
    rf = RequestField(name=k, data=fp.read(),
MemoryError
```

For other libraries, there are solutions that involve e.g. mmap:

https://stackoverflow.com/a/2504133

but this doesn't work for requests due to the hard-coded ``f.read()`` which will force loading the whole file into memory. Is there a way to avoid this, and if not can support for ``mmap`` be implemented? (for mmap, f.read has to take an argument).

There *is* a solution for Requests in the [requests-toolbelt](https://toolbelt.readthedocs.io). Namely the [Streaming Multipart Encoder](https://toolbelt.readthedocs.io/en/latest/uploading-data.html#streaming-multipart-data-encoder).

We've talked about adding this support into Requests directly though, so ideally this won't be necessary in the *nearish* future.