requests shows lots of DeprecationWarning on Python 3.6

Running tests on my project with the -Wd option now displays lots of DeprecationWarnings coming from requests.

From the Python 3.6 Changelog (https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior):
```A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases. (Contributed by Emanuel Barry in bpo-27364.)```

For reference, this is the commit that fixed those DeprecationWarnings in Django 1.11: https://github.com/django/django/commit/8119b679eb85cdc0ae3d321e54d06dd0200a1e82

Do those deprecation warnings happen to point at the location in the code where the problem arises? If so, it'd be useful to see that output.

They actually do:

```
/venv/lib/python3.6/site-packages/requests/models.py:847: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:67: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:80: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:93: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:108: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:122: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:136: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/api.py:148: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:498: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:509: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:520: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:533: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:544: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:555: DeprecationWarning: invalid escape sequence \*
  """
/venv/lib/python3.6/site-packages/requests/sessions.py:565: DeprecationWarning: invalid escape sequence \*
  """
```

Yup, so these almost all seem to be in docstrings where the backslashes should be being doubled-up. Anyone who likes to is welcome to submit a PR to remove these.

(By the way, that "anyone who likes to" includes yourself @rubendura! Just wanted to make sure that you didn't think I was excluding you.)

I am on it. I just forked the repo ;)

For some reason I can't get the deprecation warnings to show when running the tests against the requests test suite.
I tried running them as shown in http://docs.python-requests.org/en/latest/dev/todo/#development-dependencies
But doing that doesn't allow me (or I don't know how) to pass the -Wd option to python, so I tried running them as 
```~/.local/share/virtualenvs/requests-ThIWAgEP/bin/python -Wd setup.py test```

That seems to run them and displays DeprecationWarnings in other packages, but not on requests.

I want to get them against master and not use the warnings from my project because there could (and will) be differences in the source code for requests. Also this will show me how to set up my env in case I wanted to contribute to requests in the future.

Some help would be appreciated.

The easiest thing to do is to note that `py.test` is a Python script, and so you can do `python $(which py.test)` which should get you closer.

Won't `python -m pytest` work?

Thanks. But that gets me the same output. No DeprecationWarnings for requests when there should be some.

Below the full output of the command (I activated the venv created by pipenv before running it):

```
(requests-ThIWAgEP)  ✘  ~/src/requests   master ●  python -Wd $(which py.test)
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/bin/../lib/python3.6/site.py:165: DeprecationWarning: 'U' mode is deprecated
  f = open(fullname, "rU")
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_httpbin/plugin.py:4: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import serve, certs
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:8: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import embed
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:9: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import engine
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/engine.py:11: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from .compat import StringIO
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:10: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import compat
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/ruben/src/requests, inifile:
plugins: mock-1.6.0, httpbin-0.0.7, cov-2.4.0
collected 483 items

tests/test_hooks.py ...
tests/test_lowlevel.py ............
tests/test_requests.py ............................................................................................................................................................X................X.......................................................................................
tests/test_structures.py ...........................
tests/test_testserver.py ...........
tests/test_utils.py ..s......................................................................................................................................................................

============================================================================================================== 480 passed, 1 skipped, 2 xpassed in 54.42 seconds ===============================================================================================================
```

As you can see requests DeprecationWarnings are not being shown, but I don't get why.

@sigmavirus24 Yup, that also works but gives the exact same result as it should be doing the same.

That's odd. Do you see them if you just import the code?

No luck

```
(requests-ThIWAgEP)  ~/src/requests   master ●  python -Wd
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/bin/../lib/python3.6/site.py:165: DeprecationWarning: 'U' mode is deprecated
  f = open(fullname, "rU")
Python 3.6.1 (default, Mar 23 2017, 16:49:06)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
```

Ok, so that suggests that the deprecation warning there is either not coming from Requests or not valid in the current master branch.

So I thought, but it's easy to find an example where that still happens. For example, in requests/models.py:862 there is a tripe-quoted doc string containing an invalid escape sequence "\\*".

Unless I'm getting something wrong, that should be flagged as a DeprecationWarning in Python 3.6

That's very interesting

Sure, but it isn't. ;) So...what is going on?

Funny, I had to escape \ in that comment before for GitHub not to escape \ 😅

I tried running the same with -Wa and adding a random line to the code containing a few escape squences and still no luck. Running out of ideas here :S

OH! I wonder if you have to remove all the *.pyc files in the repo and any `__pycache__` directories. Want to try that?

No luck with that. I started to wonder if py.test does something with Warnings and came across this:
https://docs.pytest.org/en/features/warnings.html#ensuring-function-triggers

I can't figure out if that has something to do with it or not. My guess is that the problem lies somewhere else because DeprecationWarnings were not seen when importing requests.

Yeah, my assumption is that py.test does not by default suppress these. But I have no idea why you aren't seeing them.

Ok, this is interesting. If I interrupt py.test with Ctrl+C DeprecationWarnings will be printed. Compare this two sessions.

Without Ctrl+C
```
(requests-ThIWAgEP)  ✘  ~/src/requests   master ●  python -Wall -m pytest
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/bin/../lib/python3.6/site.py:165: DeprecationWarning: 'U' mode is deprecated
  f = open(fullname, "rU")
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_httpbin/plugin.py:4: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import serve, certs
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:8: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import embed
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:9: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import engine
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/engine.py:11: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from .compat import StringIO
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:10: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import compat
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/ruben/src/requests, inifile:
plugins: mock-1.6.0, httpbin-0.0.7, cov-2.4.0
collected 483 items

tests/test_hooks.py ...
tests/test_lowlevel.py ............
tests/test_requests.py ............................................................................................................................................................X...............127.0.0.1 - - [05/Apr/2017 15:28:27] "GET /stream/4 HTTP/1.1" 200 1080
.X.......................................................................................
tests/test_structures.py ...........................
tests/test_testserver.py ...........
tests/test_utils.py ..s......................................................................................................................................................................

============================================================================================================== 480 passed, 1 skipped, 2 xpassed in 54.95 seconds ===============================================================================================================
```


With Ctrl+C
```
(requests-ThIWAgEP)  ✘  ~/src/requests   master ●  python -Wall -m pytest
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/bin/../lib/python3.6/site.py:165: DeprecationWarning: 'U' mode is deprecated
  f = open(fullname, "rU")
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_httpbin/plugin.py:4: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import serve, certs
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:8: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import embed
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:9: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import engine
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/engine.py:11: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from .compat import StringIO
/Users/ruben/.local/share/virtualenvs/requests-ThIWAgEP/lib/python3.6/site-packages/pytest_cov/plugin.py:10: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  from . import compat
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/ruben/src/requests, inifile:
plugins: mock-1.6.0, httpbin-0.0.7, cov-2.4.0
collected 483 items

tests/test_hooks.py ...
tests/test_lowlevel.py .^Csource:69: DeprecationWarning: invalid escape sequence \*
source:82: DeprecationWarning: invalid escape sequence \*
source:95: DeprecationWarning: invalid escape sequence \*
source:110: DeprecationWarning: invalid escape sequence \*
source:124: DeprecationWarning: invalid escape sequence \*
source:138: DeprecationWarning: invalid escape sequence \*
source:150: DeprecationWarning: invalid escape sequence \*
source:508: DeprecationWarning: invalid escape sequence \*
source:519: DeprecationWarning: invalid escape sequence \*
source:530: DeprecationWarning: invalid escape sequence \*
source:543: DeprecationWarning: invalid escape sequence \*
source:554: DeprecationWarning: invalid escape sequence \*
source:565: DeprecationWarning: invalid escape sequence \*
source:575: DeprecationWarning: invalid escape sequence \*


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
to show a full traceback on KeyboardInterrupt use --fulltrace
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py:586: KeyboardInterrupt
=========================================================================================================================== 4 passed in 2.06 seconds ===========================================================================================================================
```

I don't know what's going on there, but looks like py.test might be somehow interfering with it.

So...why does running python itself exhibit the same behaviour?

I have no clue and it's really triggering me. Still investigating.

Have you been able to reproduce it on your side?

Nope, I get the relevant output. Feel free to use it:

```
/Users/cory/Documents/Python/requests_org/requests/requests/models.py:866: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:69: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:82: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:95: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:110: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:124: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:138: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/api.py:150: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:508: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:519: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:530: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:543: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:554: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:565: DeprecationWarning: invalid escape sequence \*
  """
/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py:575: DeprecationWarning: invalid escape sequence \*
  """
```

I managed to get the warnings on my system by deleting ```__pycache__``` as you suggested and importing the package. Not deleting ```__pycache__``` or running the test suite was hiding those messages from me.