Raibek/requests-github-issues huggingface dataset:
Inconsistent document about parameter timeout

The quickstart document (http://docs.python-requests.org/en/master/user/quickstart/) states that "If no timeout is specified explicitly, requests do not time out.". However, this is not correct as I noticed automatic timeout if no timeout is specified. Besides, this information is inconsistent with the advanced document (http://docs.python-requests.org/en/master/user/advanced/#advanced), which states that "...by passing None as a timeout value and then retrieving a cup of coffee." in the end of the document.
Update README.rst - add 'of'


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


```diff
@@           Coverage Diff           @@
##           master    #3920   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          15       15           
  Lines        1940     1940           
=======================================
  Hits         1733     1733           
  Misses        207      207
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3920?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/3920?src=pr&el=footer). Last update [c43fefa...4acdb99](https://codecov.io/gh/kennethreitz/requests/compare/c43fefa7ed535c41ba7d58021f0f16ed5ba1d584...4acdb99752e2411df542e99dd9baafae7e2ca8e8?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
DefaultSelector fallback to less efficient methods

Test the selector before making it the default selector. This is due to issue reported by myself at https://github.com/kennethreitz/requests/issues/3906

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


```diff
@@           Coverage Diff           @@
##           master    #3918   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          15       15           
  Lines        1940     1940           
=======================================
  Hits         1733     1733           
  Misses        207      207
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3918?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/3918?src=pr&el=footer). Last update [c43fefa...931adf5](https://codecov.io/gh/kennethreitz/requests/compare/c43fefa7ed535c41ba7d58021f0f16ed5ba1d584...931adf5c92d43a1e9d9fe0d5e4dc49ee2449d881?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Thanks for this! However, this patch is entirely contained in [urllib3](https://github.com/shazow/urllib3), which we vendor in unchanged. You'll need to propose this patch on that repository.

Ok, but it's weird to have another module within requests itself, which made me thought that urllib3 is part of requests. The only other python project I usually got involved in is flexget which never place other external module inside itself.

Anyway, your comment clears things up for me. Thanks.
Requests follows 301 redirect on PROPFIND request, resubmits request without request body

When submitting a `PROPFIND` request using requests, and the server redirects using 301, the request is resubmitted at the new URL without request payload, but with the same method (so not changing to `GET`). I am not sure if this behavior is intended. You appear to have a few pull requests to match browser behavior in certain situations, but I didn't check whether those PRs have been reverted in the meantime or not. I also couldn't find any documentation about redirect behavior.

It appears that https://github.com/kennethreitz/requests/pull/3864 contains a relevant change:

>Relax how Requests strips bodies from redirects. 3.0.0 only supports body removal on 301/302 POST redirects and all 303 redirects.

Closing this since it apparently works as intended, sorry for the noise.
Add mention to list od tuples as data param.

`requests.request` accepts list of tuples in the `data` param, but thereś no mention of it in the docs.

Changed.

Cool, this looks good. I'll wait for the build to go green and merge. Thanks so much @StyXman! :sparkles:

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


```diff
@@           Coverage Diff           @@
##           master    #3913   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          15       15           
  Lines        1940     1940           
=======================================
  Hits         1733     1733           
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3913?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/api.py](https://codecov.io/gh/kennethreitz/requests/compare/62bd9247ba0cef14827f32459a921376b54d56dd...2e9e944bc16fcf51b9ec4f8fc2f6161fbd2bb194?src=pr&el=tree#diff-cmVxdWVzdHMvYXBpLnB5) | `81.81% <ø> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3913?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/3913?src=pr&el=footer). Last update [62bd924...2e9e944](https://codecov.io/gh/kennethreitz/requests/compare/62bd9247ba0cef14827f32459a921376b54d56dd...2e9e944bc16fcf51b9ec4f8fc2f6161fbd2bb194?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
Failed to establish a new connection: [Errno -4] Non-recoverable error

Hey there, I'm using requests (2.9.1) to make an https request to a kubernetes apiserver but am hitting an error and would appreciate some debugging tips on how to figure out what is causing it. 

The error:

```
Traceback (most recent call last):
  File "<string>", line 304, in _manage_resource
  File "<string>", line 393, in _sync_resources
  File "<string>", line 445, in _api_get
  File "site-packages/requests/sessions.py", line 480, in get
  File "site-packages/requests/sessions.py", line 468, in request
  File "site-packages/requests/sessions.py", line 576, in send
  File "site-packages/requests/adapters.py", line 437, in send
ConnectionError: HTTPSConnectionPool(host='<hostname redacted>', port=8443): Max retries exceed
ed with url: /api/v1/namespaces (Caused by NewConnectionError('<requests.packages.urllib3.connection.
VerifiedHTTPSConnection object at 0x7f5dfb0e5290>: Failed to establish a new connection: [Errno -4] N
on-recoverable error',))
```

I'm using requests 2.9.1 but have seen the same using latest.

I've tried turning up logging for `requests.packages.urllib3` but I'm not seeing any useful messages besides a generic: `INFO Starting new HTTPS connection (1): <hostname redacted>`

I've tried inserting a breakpoint and inspecting the `ConnectionError` but was not able to garner any useful information (though I may have missed something).

This may be my own lack of knowledge, but what library can I use to look up what errno -4 is? Google searching for a negative error code is literally impossible.

Thanks for your time!

Hrm, that's odd: on most Unices errno is restrained to a positive number. What platform are you on? Even that error message is unusual.

Does this happen consistently?

Made it to the bottom of this. It was running in an alpine:3.3 docker container which, turns out, has a DNS resolving issue for FQDN's which wasn't patched until 3.4. So my request error was just a hostname lookup failure.

It's possible that the error was obfuscated due to the fact that my python code is packaged into a binary using pyinstaller, but I'm not sure.

Thanks for taking a look. Closing :)
Update implementation of TimedCache object

There were some odd decisions made about the implementation of some of
the required methods for MuttableMapping in the TimedCache object. This
cleans those up and makes the implementation, ever so slightly, easier
to read.

See also #3885

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3909?src=pr&el=h1) Report
> Merging [#3909](https://codecov.io/gh/kennethreitz/requests/pull/3909?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/41a33f2e869e1fdcd88062be469775f613ee8ced?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.


```diff
@@           Coverage Diff           @@
##           master    #3909   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          15       15           
  Lines        1940     1940           
=======================================
  Hits         1733     1733           
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3909?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/structures.py](https://codecov.io/gh/kennethreitz/requests/compare/41a33f2e869e1fdcd88062be469775f613ee8ced...8e6e47af43d1d89a0201bd58e97c700bebbddd5e?src=pr&el=tree#diff-cmVxdWVzdHMvc3RydWN0dXJlcy5weQ==) | `100% <100%> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3909?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/3909?src=pr&el=footer). Last update [41a33f2...8e6e47a](https://codecov.io/gh/kennethreitz/requests/compare/41a33f2e869e1fdcd88062be469775f613ee8ced...8e6e47af43d1d89a0201bd58e97c700bebbddd5e?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

:cake:
requests.get on image url returns 405 (the image url works in browser)

Unfortunately I cannot provide the image url, maybe this can help: https://github.com/thumbor/thumbor/pull/342/files

405 means method unsupported. Are you sure you're doing a GET?

sure :)

Well in that case, the error is almost certainly not with Requests, and unless you can get us more detail we can't really help you. Sorry! 😟
How to retry streaming uploads

Consider this piece of code:

```python
retries = Retry(total=3)
session = requests.Session()
session.mount('http://', HTTPAdapter(max_retries=retries))
with open('big_file.txt', 'rb') as f:
    session.put(url, data=f)
```

It has a bug.
When network error occurred during transmission of the file, the corresponding file handle points to some position _inside_ the file. So the next retry performs new HTTP connection which uploads _the rest_ of the file. Thankfully, in this case, `Content-Length` doesn't change, so the server waits for the rest of data and then disconnects after some timeout.
Here is [the script](https://gist.github.com/theyoprst/df536545e1a4a0f3f21cf584a547a529) which demonstrates this bug. And here is [it's output](https://gist.github.com/theyoprst/7c69d019457d89310f16707e979c1580).

So retries are almost useless for such uploads (they _are_ useful in case of connection problems, though).
Now I can only think of external retrying by manual reopening / re-seeking of the file.
Is there any way to make requests to retry it 'right'?
Should this behavior be fixed in requests?


Wow. It seems in the latest version it was already fixed.
Probably here: https://github.com/shazow/urllib3/issues/459


Hey @theyoprst, you're correct, this should have been resolved in urllib3 in shazow/urllib3#1039. Are you still experiencing this issue in the latest version of requests?

Yep, as it looks like you were referring to the latest version of Requests. This doesn't seem to be reproducible with 2.13.0 which has the patch included in urllib3. Thanks for taking the time to open this issue, @theyoprst!
fix #3902 Add proposed documentation change for post data


# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3903?src=pr&el=h1) Report
> Merging [#3903](https://codecov.io/gh/kennethreitz/requests/pull/3903?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee?src=pr&el=desc) will **increase** coverage by `0.15%`.
> The diff coverage is `n/a`.


```diff
@@            Coverage Diff             @@
##           master    #3903      +/-   ##
==========================================
+ Coverage   89.17%   89.32%   +0.15%     
==========================================
  Files          15       15              
  Lines        1940     1940              
==========================================
+ Hits         1730     1733       +3     
+ Misses        210      207       -3
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3903?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/__init__.py](https://codecov.io/gh/kennethreitz/requests/compare/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee...21972c4601378fcad28cbc63466775b76d6a888a?src=pr&el=tree#diff-cmVxdWVzdHMvX19pbml0X18ucHk=) | `93.33% <0%> (+10%)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3903?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/3903?src=pr&el=footer). Last update [3f3df8b...21972c4](https://codecov.io/gh/kennethreitz/requests/compare/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee...21972c4601378fcad28cbc63466775b76d6a888a?src=pr&el=footer&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Can you do a rebase? 

If you need help with that, let me know. 

I'm going to merge this by hand.
Propose additional documentation for post data

## Problem statement

Current documentation only specifies the most common case of post data - a dictionary. The code in fact supports other forms of post data which is not documented. Propose to enhance the quick start section that deals with post data to include examples of other uses.

Section of text in the current documentation: [More complicated POST requests](http://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests)

## Questions in the wild indicating the need for more documentation in this regard
On stockoverflow:

* [how to post multiple value with same key in python requests?](http://stackoverflow.com/questions/23384230/how-to-post-multiple-value-with-same-key-in-python-requests)
* [handling duplicate keys in HTTP post in order to specify multiple values](
http://stackoverflow.com/questions/27116424/handling-duplicate-keys-in-http-post-in-order-to-specify-multiple-values)
* [How to send multiple of the same key/parameter via POST?](
http://stackoverflow.com/questions/19004403/how-to-send-multiple-of-the-same-key-parameter-via-post)
* [How to send an array using requests.post (Python)? “Value Error: Too many values to unpack”](
http://stackoverflow.com/questions/31168819/how-to-send-an-array-using-requests-post-python-value-error-too-many-values/35534695)

And there is this issue #1641: Cannot send Single Key, Multiple value data in post because of the use of pythons dict.  

## Proposed modification:

```rst
You can also pass a list of tuples to the ``data`` argument. This is particularly
useful when the form has multiple elements that use the same key::

    >>> payload = (('key1', 'value1'), ('key1', 'value2'))
    >>> r = requests.post('http://httpbin.org/post', data=payload)
    >>> print(r.text)
    {
      ...
      "form": {
        "key1": [
          "value1",
          "value2"
        ]
      },
      ...
    }

Value of each payload element can be a scalar or an iterable::

    >>> payload = (('key1', ('value1', 1, (1, 2))), {'key2', ('value2', 2)})
    >>> r = requests.post('http://httpbin.org/post', data=payload)
    >>> print(r.text)
    {
      ...
      "form": {
        "key1": [
          "value1",
          "1",
          "1",
          "2"
        ],
        "key2": [
          "value2",
          "2"
        ]
      },
      ...
    }

```

I am not sure if the use of httpbin is very helpful here. A reader who is not familiar with this service will wonder how the JSON response is produced. It would be more helpful to show the acual *request* body, not how some service interprets it.

Thanks for the comment, I'm simply following the existing documentation: [More complicated POST requests](http://docs.python-requests.org/en/master/user/quickstart/#more-complicated-post-requests). My proposed change is right after the first code block.

this sounds good to me!

go for it @garywu!
Smaller logo

The logo as-is is too large, it won't even fit on my screen!

I made a smaller version for use in the README.rst, because GitHub has neutered some useful features and doesn't care: https://github.com/github/markup/issues/295

NOTE: the image path is to my fork. Once merged, the path should be changed to refer to the main repo.

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3901?src=pr&el=h1) Report
> Merging [#3901](https://codecov.io/gh/kennethreitz/requests/pull/3901?src=pr&el=desc) into [master](https://codecov.io/gh/kennethreitz/requests/commit/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee?src=pr&el=desc) will **increase** coverage by `0.15%`.
> The diff coverage is `n/a`.


```diff
@@            Coverage Diff             @@
##           master    #3901      +/-   ##
==========================================
+ Coverage   89.17%   89.32%   +0.15%     
==========================================
  Files          15       15              
  Lines        1940     1940              
==========================================
+ Hits         1730     1733       +3     
+ Misses        210      207       -3
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3901?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/__init__.py](https://codecov.io/gh/kennethreitz/requests/compare/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee...722a2dfb63b87f13875bc9e60193774feaeafa5a?src=pr&el=tree#diff-cmVxdWVzdHMvX19pbml0X18ucHk=) | `93.33% <0%> (+10%)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3901?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/3901?src=pr&el=footer). Last update [3f3df8b...eca8351](https://codecov.io/gh/kennethreitz/requests/compare/3f3df8b5ffbbd617a32a9b01503f02e30a0818ee...eca835149157f49e53f6e77dff7d839021ed79bf?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Nice first commit, thanks @nedbat!
fixed #3894 by mentioning form-encoding of dict

The optional `data` parameter will be form-encoded, if a dictionary is provided.

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


```diff
@@           Coverage Diff           @@
##           master    #3900   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          15       15           
  Lines        1940     1940           
=======================================
  Hits         1733     1733           
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3900?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/api.py](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...3d22f9f5ab52a0a58b7ffca13ea5aba9f37b6536?src=pr&el=tree#diff-cmVxdWVzdHMvYXBpLnB5) | `81.81% <ø> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3900?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/3900?src=pr&el=footer). Last update [2aaf6ac...3d22f9f](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...3d22f9f5ab52a0a58b7ffca13ea5aba9f37b6536?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
URL params with special chars fail

Hi all

i have to open this link

http://www.mytest.com/rest?api_key=username:password

 i do a post or a get call

```
host= "http://www.mytest.com/rest"
queryParams = {"api_key" : "{}:{}".format(username, password)}
requests.post(host, params=queryString)

```
and the server return 500 error, this is because the requests send that call
http://www.mytest.com/rest?api_key=username%3Apassword
and is not correct

have some solution?
thanks in advance for your help


I believe the only solution at this time is to drop the params keyword argument and just use a plain old string.

```python
requests.post('{0}?api_key={1}:{2}'.format(host, username, password))
```

Your query parameter  `api_key` will be URL encoded as `api_key?username%3Apassword` by requests. This is correct, passing it unencoded using a plain colon `:` is not recommended.

So if the server you try to access can't URL decode the parameter value, the server should be fixed.

Requests will avoid aggressively handling your string if you do what @patallen suggests, which should resolve your problem, but @lutzhorn is right: the server should accept both, and is at fault here. :smile:

I'd also add that sending a password via a http connection isn't a good
idea either, especially as part of the url


Hi All

thank you for your help
@lutzhorn is true, and i have reported the problem as well, but i'm sure that is a bit difficult to solve from the server part, is Asterisk the open source PBX and have a very large list of issues.
@TetraEtc yes but the URL is into the internal network and have no external access

@Lukasa and @patallen , thank you i will use your suggestion, hope is work well
PUT'ing files to Azure blob storage... keeps the whole "body?"

Heyo! Thanks so much for requests, I use it all the time and appreciate the effort ya'll put into this!

Anyway, I am having a bit of trouble PUT'ing some files to Azure, for some reason Azure receives the files as:

```
--d21a382fd3cb49f085c89cc5c15e180e
Content-Disposition: form-data; name="file"; filename="stdout.txt"
Content-Type: text/plain

<file data>

--d21a382fd3cb49f085c89cc5c15e180e--
```

Instead of just

```
<file data>
```

For the life of me, I can't figure out *why* it's keeping the headers there and such...

```python
def put_blob(url, file_path):
    requests.put(
        url,
        files={'file': open(file_path, 'rb')},
        headers={
            'x-ms-blob-type': 'BlockBlob',
        }
    )
```



Thanks for this report!

The `files` parameter uploads the data using `multipart/form-encoded` as the data structure. This is the most common interaction with HTML forms, and is therefore how that works.

To upload just the raw file data, pass the file object to the `data` parameter:

```python
    requests.put(
        url,
        data=open(file_path, 'rb'),
        headers={
            'x-ms-blob-type': 'BlockBlob',
        }
    )
```

You. Are. So. Handsome. Thanks a ton!! That was about an hour spent trying to fix that, agh!

This really helped me, too. Thanks a ton, @Lukasa
Documentation issue: requests.request behavior unclear when 'data' parameter is dictionary

The [documentation for 'requests.request' ](http://docs.python-requests.org/en/master/api/#requests.request) lists a parameter 'data':

> data -- (optional) Dictionary, bytes, or file-like object to send in the body of the Request.

It is unclear what the behavior will be when a dictionary is passed.  Since an HTTP request's body is a series of bytes, it is unclear how the library will serialize a dictionary to a series of bytes.  For example, will it write the dictionary as JSON, or as XML?

For the other parameter types (bytes or file-like object) I think it is fairly obvious what the behavior will be.

Suggested resolution:  the documentation should add a sentence like:  "Dictionary objects will be serialized as JSON using the 'json' module", along with any restrictions on the content of the dictionary.

I encountered this when reading the [first section](http://docs.python-requests.org/en/master/user/quickstart/#make-a-request) of the Quickstart guide.

> "Dictionary objects will be serialized as JSON using the 'json' module", along with any restrictions on the content of the dictionary.

Heh, the fact that you wrote this suggests that it might be worthwhile, given that that's exactly *not* what we do. Dictionaries are encoded as application/x-www-form-urlencoded data.

So, in general I'd say that our behaviour is in-line with what most users who have used other libraries would expect, but it also can't hurt to elaborate a bit. This is a good PR for a first-time contributor to pick up, so I'm going to attach some labels and let someone come along to fix it.

I also expected it to be urlencoded. But I had to think 15sec to conclude that urlencoding was what made the most of sense. So +1 for a PR to clarify the doc.

In http://docs.python-requests.org/en/master/api/#lower-level-classes, the  form-encoding  is mentioned:

> data -- the body to attach to the request. If a dictionary is provided, form-encoding will take place.
Fixed some typos


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


```diff
@@            Coverage Diff             @@
##           master    #3892      +/-   ##
==========================================
+ Coverage   89.08%   89.32%   +0.24%     
==========================================
  Files          15       15              
  Lines        1896     1940      +44     
==========================================
+ Hits         1689     1733      +44     
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3892?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/utils.py](https://codecov.io/gh/kennethreitz/requests/compare/d6f4818c0b40bc6c00433c013b7daaea83b2cd51...e5aa914e6aac14363a651ecc8d01a46a8757ce82?src=pr&el=tree#diff-cmVxdWVzdHMvdXRpbHMucHk=) | `85.02% <ø> (+0.08%)` | :white_check_mark: |
| [requests/structures.py](https://codecov.io/gh/kennethreitz/requests/compare/d6f4818c0b40bc6c00433c013b7daaea83b2cd51...e5aa914e6aac14363a651ecc8d01a46a8757ce82?src=pr&el=tree#diff-cmVxdWVzdHMvc3RydWN0dXJlcy5weQ==) | `100% <0%> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3892?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/3892?src=pr&el=footer). Last update [d6f4818...e5aa914](https://codecov.io/gh/kennethreitz/requests/compare/d6f4818c0b40bc6c00433c013b7daaea83b2cd51...e5aa914e6aac14363a651ecc8d01a46a8757ce82?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

This looks good now, I think. @vpfautz if you feel like it, this can be patched in [urllib3](https://github.com/shazow/urllib3) too.

Also thanks for catching this! I shouldn't be typing without spell check in my IDE :)
Requests fails to handle amazon.com cookies

```python
import requests
>>> r = requests.get("https://www.amazon.com/ap/signin?openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0")
>>> r.cookies
<RequestsCookieJar[]>
>>> r.headers["Set-Cookie"]
'ap-fid=""; Domain=.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ap/; Secure, a-ogbcbff=deleted; Domain=.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/, x-main=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, session-id=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, session-token=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, session-id-time=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, ubid-main=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, at-main=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure, sess-at-main=""; Domain=.www.amazon.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure'
```

We're handling them fine: those cookies are all set to expire in the past, which is how you ask a user agent to delete them. What problem are you actually having?

Hmm, good catch. When you turn around and submit the login form on this page, the response from Amazon is a page asking you to enable cookies.

@SirCmpwn is it possible Amazon is relying on cookies set by JavaScript?

I get different results in my browser on amazon.com when I have JavaScript disabled. I can't log in without it - I get a captcha that seems to be impossible to solve. But this is different from the behavior I get with requests.

What if you use your browser's User-Agent string in Requests? Do you get the same behaviour then?

Yes.

So, Amazon requires javascript and a UA that looks vaguely like a browser. This is pretty clearly **not** a bug in requests.
wrong ecxeption? return code wrong?

Dear everyone!

i am facing strange beahvior with python requests.

here is my snippet:

```
    for x in range(0,len(url)):
    retrys = 0

    while retrys < 10 :
        try:
            res = requests.get(
                url[x],
                timeout=(5, 60),
                proxies=dict(   http='socks5://localhost:' + str(s_port),
                                https='socks5://localhost:' + str(s_port)
                            )
            )

        except requests.exceptions.RequestException as err:

            print( str(res.status_code) )
            print( str(len(res.content)) )

            retrys += 1
            time.sleep(1)

            if retrys % 5 == 0 :
                print( str( threading.currentThread() ) + " - Querry failed? -> Need to reconnect TOR")
                import pdb; pdb.set_trace()

                print( str( threading.currentThread() ) )

        else:
            if isinstance(res.content, bytes) == True:

                output.append( res.content )

                break
            else:
                import pdb; pdb.set_trace()
```

it is giving my the right output look:

```
We are fetching now :  178  urls in :  26 Blobs
200
26943
200
26943
200
26943
200
26943
200
26943
```

So statuscode is all the time 200 OK and the len is okay. When i drop to my debug console i can catch the content from result, parse json, as ecxpected. But my requsts is still ecxepting my function. err is telling me inside ecxeption that connection has been refused.

(Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))",),)

Any thoughts?

EDIT: it is a tor proxy.


close -> stupid!
Removed response hook hardcode.


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


```diff
@@            Coverage Diff             @@
##           master    #3884      +/-   ##
==========================================
+ Coverage   89.32%   89.34%   +0.01%     
==========================================
  Files          15       15              
  Lines        1940     1942       +2     
==========================================
+ Hits         1733     1735       +2     
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3884?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/auth.py](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...0455544379f21b0a0ae6741fa536c59e47df999c?src=pr&el=tree#diff-cmVxdWVzdHMvYXV0aC5weQ==) | `86.58% <100%> (+0.08%)` | :white_check_mark: |
| [requests/hooks.py](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...0455544379f21b0a0ae6741fa536c59e47df999c?src=pr&el=tree#diff-cmVxdWVzdHMvaG9va3MucHk=) | `100% <100%> (ø)` | :white_check_mark: |
| [requests/sessions.py](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...0455544379f21b0a0ae6741fa536c59e47df999c?src=pr&el=tree#diff-cmVxdWVzdHMvc2Vzc2lvbnMucHk=) | `92.93% <100%> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3884?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/3884?src=pr&el=footer). Last update [2aaf6ac...0455544](https://codecov.io/gh/kennethreitz/requests/compare/2aaf6ac03862d29ef8664aa8650a3c34ac4a0b2d...0455544379f21b0a0ae6741fa536c59e47df999c?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Thanks for this! I think this is absolutely worth doing but there's an element of style consideration here, so I'm going to let @kennethreitz make the call on this one.
HTTPS proxy with requests

A small (but expanding) set of HTTP clients now offer the ability to connect to proxies over TLS. 'curl' recently added this feature in v7.52.0 (More info. can be found at https://daniel.haxx.se/blog/2016/11/26/https-proxy-with-curl/). Please consider adding support for this feature to 'requests'.

Hi there, thanks for this request!

Adding support for this feature requires a pretty substantial internal changes to the code logic of our dependencies. This work is ongoing, and when it's done it can be discussed, but for now it's not something we can promise to put on any kind of roadmap.

Sorry! :pray:
Suggestion: add a new field `method` to `Response` class

If it make sense to include the [`url`][url] field to the `Response` class in order to be human friendly when automatic redirection kicks in, shouldn't there be a `method` field as well, for the case when a `POST` results in 302 with which Requests respond with `GET` ?

Background: I was investigating an issue with a Consul REST API client which was based on Requests, and found out it was related to #2590 . While it's great the v3.0 will be shipped with the fix #3757, my observation was it was tricky to figure out what was going on under the hood. I could see my `PUT` was redirected from `/v1/kv/a//b` to `/v1/kv/a/b` by 301 but at first I had no idea the method was also changed to `GET`, striping the content data away. I gave a try on `curl -v` and hurrah, it displayed "Switch from POST to GET".

Moreover, if my understanding is correct (web isn't my field of specialty,) in a hypothetical situation when Requests is following a looong chain of mixture of 301 and 303, it would be helpful to be able to identify at which point the method changed from, say, `PUT` to `GET`.

Anyways the bottom line is, the `url` isn't complete without an accompanying `method` field, I think.

[url]: http://docs.python-requests.org/en/latest/api/#requests.Response.url

@nodakai that all is available in the response history already. I don't understand how the final response having a method would help you identify that. `response.request.method` already exists and (I thought) is documented.

Also, hi! Welcome! Thanks for opening this and starting the discussion for it. I'm a bit distracted so my responses will be a bit.. short. :)

Thanks for this request!

So I agree with @sigmavirus24. While the `response.url` field is a handy convenience, in general we make sure that the request that triggered a given response is always available at `response.request`, and can be introspected. 

If you didn't find that obvious, I'd be delighted to merge a pull request with clarifying documentation.
Correct docstring for Response.ok

We added a docstring just a few hours ago but it wasn't entirely accurate.

@sigmavirus24 That PR was merged on the grounds that it was consistent with the docstrings that relied on that method. If we're changing one, we should change them all. =)

@Lukasa which docstrings are those? I was under the impression that the docstring format was what was borrowed from, not the content of other docstrings.

`__bool__` and `__nonzero__`, immediately above.

I'll happily fix those too. In my opinion, misleading docs are worse than no docs. Those methods have been subject to criticism for years at this point and are targetted for correction in 3.0. May as well correct their documentation until 3.0 is out.

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


```diff
@@           Coverage Diff           @@
##           master    #3877   +/-   ##
=======================================
  Coverage   89.08%   89.08%           
=======================================
  Files          15       15           
  Lines        1896     1896           
=======================================
  Hits         1689     1689           
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3877?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/models.py](https://codecov.io/gh/kennethreitz/requests/compare/e674aa1c8c21f0583f19fea6c78a6ccdc9ba9286...8e049bd9eb49485dc98efd6f14ab7f76c084cf8b?src=pr&el=tree#diff-cmVxdWVzdHMvbW9kZWxzLnB5) | `93.42% <ø> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3877?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/3877?src=pr&el=footer). Last update [e674aa1...8e049bd](https://codecov.io/gh/kennethreitz/requests/compare/e674aa1c8c21f0583f19fea6c78a6ccdc9ba9286...8e049bd9eb49485dc98efd6f14ab7f76c084cf8b?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Updated `__bool__` and `__nonzero__`.
added docstring for response.ok property

Nothing much here, just added a docstring for `response.ok` property.

Took the docstring straight from the other methods to stay consistent.

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


```diff
@@           Coverage Diff           @@
##           master    #3876   +/-   ##
=======================================
  Coverage   89.08%   89.08%           
=======================================
  Files          15       15           
  Lines        1896     1896           
=======================================
  Hits         1689     1689           
  Misses        207      207
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3876?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/models.py](https://codecov.io/gh/kennethreitz/requests/compare/655f0edbb43dad16ea5fe6ec0f31fdc1de396610...3664682539fe911a3e19712a0ddec21a515bc16f?src=pr&el=tree#diff-cmVxdWVzdHMvbW9kZWxzLnB5) | `93.42% <ø> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3876?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/3876?src=pr&el=footer). Last update [655f0ed...3664682](https://codecov.io/gh/kennethreitz/requests/compare/655f0edbb43dad16ea5fe6ec0f31fdc1de396610...3664682539fe911a3e19712a0ddec21a515bc16f?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

LGTM, thanks! :sparkles: :cake: :sparkles:
variable name consistency

Just need to clean up a few variable names.

All set.

So to be clear, the clearer names are on the 3.0 branch already: I just accidentally busted them with names from the master branch like a dummy.

# [Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3874?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`proposed/3.0.0@56dd77f`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `100%`.


```diff
@@                Coverage Diff                @@
##             proposed/3.0.0    #3874   +/-   ##
=================================================
  Coverage                  ?   89.22%           
=================================================
  Files                     ?       15           
  Lines                     ?     1931           
  Branches                  ?        0           
=================================================
  Hits                      ?     1723           
  Misses                    ?      208           
  Partials                  ?        0
```


| [Impacted Files](https://codecov.io/gh/kennethreitz/requests/pull/3874?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/sessions.py](https://codecov.io/gh/kennethreitz/requests/compare/56dd77fc52b853fffa256ea6b370e82dba291df3...b8a87e00d74a6873aa2ba439e2e99298612a4420?src=pr&el=tree#diff-cmVxdWVzdHMvc2Vzc2lvbnMucHk=) | `93.11% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kennethreitz/requests/pull/3874?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/3874?src=pr&el=footer). Last update [56dd77f...b8a87e0](https://codecov.io/gh/kennethreitz/requests/compare/56dd77fc52b853fffa256ea6b370e82dba291df3...b8a87e00d74a6873aa2ba439e2e99298612a4420?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Yep @sigmavirus24, `response` and `history` were added to 3.0.0 in commits by Kenneth.

Edit: 66eedec to be specific.

Is there an ETA of this getting merged in?  I'd like to refile #3871 against the 3.0 branch, but will need to schedule the time to do that after this is merged.

I think it's good to go @jvanasco, we were just waiting for confirmation from @kennethreitz. @Lukasa we can probably just merge though since this isn't actually a change, yeah?

+1