Raibek/requests-github-issues huggingface dataset:
Pass python_requires argument to setuptools

Helps pip decide what version of the library to install.

https://packaging.python.org/tutorials/distributing-packages/#python-requires

> If your project only runs on certain Python versions, setting the
> python_requires argument to the appropriate PEP 440 version specifier
> string will prevent pip from installing the project on other Python
> versions.

https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords

> python_requires
>
> A string corresponding to a version specifier (as defined in PEP 440)
> for the Python version, used to specify the Requires-Python defined in
> PEP 345.

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

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

```diff
@@           Coverage Diff           @@
##           master    #4459   +/-   ##
=======================================
  Coverage   90.14%   90.14%           
=======================================
  Files          15       15           
  Lines        1543     1543           
=======================================
  Hits         1391     1391           
  Misses        152      152
```



------

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


Is there a minimum version of setuptools necessary to support this?

@sigmavirus24 It was [added in 24.2.0](https://github.com/pypa/setuptools/blob/56bf1a9c12fd881fe6f69c3693cc426acf8012c3/CHANGES.rst#v2420) which was released on [2016-07-20](https://pypi.python.org/pypi/setuptools/json).

Additionally, `setup()` ignores unknown keyword arguments. So, while only users with setuptools 24.2+ can take advantage of this feature, it is no harm to users of previous versions.

@jdufresne can you update the branch? I'm totally on-board with this given your commentary. Cheers!

I have rebased on to the latest master. Thanks.
no response object captured in error of endless redirect chain and confusing message

I found an incredibly bad URL that causes a handful of issues.  the url below jumps between a bunch of SocialFlow (trib.al) and Bitly url shorteners for tracking, then ends up on a connection timeout that also looks like a max retries exceeded (which makes no sense to me)

The exception that is raised under Py2 and Py3 does not have a response object, although one should exist – there are a long history of redirects that gets lost and makes this difficult to debug the url's problem.

   HTTPSConnectionPool(host='this.cm', port=443): Max retries exceeded with url: /slate/follow (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x1021788d0>, 'Connection to this.cm timed out. (connect timeout=2)'))


```python
import requests

try:
	url = 'http://slate.me/1KDocND'
	r = requests.get(url, timeout=2)
	print("success")
	print(r.response)
except Exception as error:
	print("error")
	print(error)
	print(type(error.response))
```


The `max retries exceeded with url` is due entirely to the fact that Requests uses a subset of urllib3 at this point. Requests' usage of retries were wholly limited to the API that urllib3 provided prior to creating the Retry object. It's been updated little since. As a result, we don't allow urllib3 to perform its own retries so when something like this fails that is potentially retryable from the perspective of urllib3 but retries is at 0 already, we get that exception. It's plagued us for years. That said, I think we can probably do better here, but @nateprewitt or I will have to do some digging to see why we're missing the work of appending a response to the exception. Thanks for the report and the detail provided. 🎉 

I did some digging myself and figured a few things out...

1. The "max retries" text is from `requests/adapters.py` lines 497-514.  `urllib3` reports the connection timeout as a `MaxRetryError`, then wraps that error in a `ConnectionError` from `requests/exceptions.py`.  

2. Based on your info above, I traced a bunch of stuff back to resolve_redirects - which i'm very familiar with.  I will generate a PR of a starting point for a possible approach (it's just going to be a rough sketch).  I'm not familiar with enough of requests to take this on myself, but I may be able to jumpstart someone else.
Max retries exceeded with url

Summary.
I am trying to hit a third party API, such as api.ipify.org, which gives IP addresses and read the results. 
## Expected Result
JSON Response From URL i.e. ip address. 
What you expected.

## Actual Result
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=hostname, port=443): Max retries exceeded with url: /myurl (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10a857610>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

What happened instead.

## Reproduction Steps

```python
import time

page = ''
while page == '':
    try:
        page = requests.get("https://api.ipify.org/")
    except:
        print("Connection refused by the server..")
        print("Let me sleep for 5 seconds")
        print("ZZzzzz...")
        time.sleep(100)
        print("Was a nice sleep, now let me continue...")
        continue

```


  

Hi there! Thanks for opening this issue. Unfortunately, it seems this is a request for help instead of a report of a defect in the project. Please use [StackOverflow](https://stackoverflow.com) for general usage questions instead and only report defects here.

As an aside `nodename nor servname provided, or not known` typically indicates an issue with DNS. It sounds like you're requesting several different URLs that are for several different domains. You should ensure all have domain names and that those domains all work. 

Also, entertainingly, your reproduction steps (reproduced below) will always fail because of two problems:

1. You never import `requests` so you get a `NameError`
2. You use `try/except` without catching a specific exception so it will catch the `NameError` and then make you think you've encountered an exception from requests.

```py
import time

page = ''
while page == '':
    try:
        page = requests.get("https://api.ipify.org/")
    except:
        print("Connection refused by the server..")
        print("Let me sleep for 5 seconds")
        print("ZZzzzz...")
        time.sleep(100)
        print("Was a nice sleep, now let me continue...")
        continue
```

Yes, I have imported the requests but in another code block where I have encountered the original problem. 
Just to be clear. I am using IPython notebook. So, If I import in one block it will be imported everywhere i.e. in all the other code blocks. 

Regardless, this isn’t the appropriate place for your question. Please post it on StackOverflow
Prefer https over http for links in the documentation

- Fixed Read the Docs links
- Fixed GitHub links
- Fixed PyPI links

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

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

```diff
@@            Coverage Diff             @@
##           master    #4451      +/-   ##
==========================================
- Coverage   90.73%   90.14%   -0.59%     
==========================================
  Files          15       15              
  Lines        1673     1543     -130     
==========================================
- Hits         1518     1391     -127     
+ Misses        155      152       -3
```


| [Impacted Files](https://codecov.io/gh/requests/requests/pull/4451?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/adapters.py](https://codecov.io/gh/requests/requests/pull/4451/diff?src=pr&el=tree#diff-cmVxdWVzdHMvYWRhcHRlcnMucHk=) | `93.11% <0%> (-1.71%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/requests/requests/pull/4451?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/requests/requests/pull/4451?src=pr&el=footer). Last update [3dc84cd...030dcce](https://codecov.io/gh/requests/requests/pull/4451?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
SSL certificate/key not working but same certificate/key works with curl

Summary.
SSL certificate/key not working but same certificate/key works with curl

## Expected Result
certificate/key verifies properly

## Actual Result
SSLError: HTTPSConnectionPool(host='app.domain.com', port=443): Max retries exceeded with url: /p1/p2/p3 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),))

## Reproduction Steps
This works:
&nbsp;&nbsp;&nbsp;      curl -X POST -v -s -k --key client.key --cert client.crt   <blah blah ....>
<br>
This does not and gives the above error.
&nbsp;&nbsp;&nbsp;      cert_file_path = '/path-to-certfile/cert.pem'
&nbsp;&nbsp;&nbsp;      key_file_path = '/path-to-keyfile/key.pem'
&nbsp;&nbsp;&nbsp;      cert = (cert_file_path, key_file_path)
&nbsp;&nbsp;&nbsp;      requests.post(url, data=payload, cert=cert)
<br>
The client.key and client.crt are actually both in pem format (ascii readable). The server uses Nginx. I found some references about missing intermediate certificates but I'm not sure how to fix it on the server or add it to my client (just to see it work!).
<br>
```python
import requests

```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.0.3"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.3"
  },
  "platform": {
    "release": "16.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "100020cf",
    "version": "17.2.0"
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "100020cf"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}

```

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).
  

Hi there! Thanks for opening this issue. Unfortunately, it seems this is a request for help instead of a report of a defect in the project. Please use [StackOverflow](https://stackoverflow.com) for general usage questions instead and only report defects here.

`curl -k` (a.k.a, `curl --insecure`) means do not verify the server's certificate when performing the TLS connection. `cert` in `requests` is equivalent to the `--cert` and `--key` parameters but Requests will still try to perform certificate validation. That means that you probably want to also pass `verify=False` to requests. 

To follow up, I have the issue described in this post.
https://stackoverflow.com/questions/42538930/ssl-error-with-python-requests-despite-up-to-date-dependencies

The fix is just to concatenate all the certs (including intermediate ones) into a single cert file and stick it on the cert directly on the server. If you are the client and can't fix the server, just use the test cert in the post.
404 responses for chunk-encoded requests may not be received

404 responses (or any response sent by the server prior to the entire request being sent) for chunk-encoded requests may not be received by the caller.

This appears to happen if the server closes the connection (after sending the 404 response) prior to the completion of the chunked post / upload.

## Expected Result

Posting a chunked encoded request to an invalid URL should return the 404 response.

## Actual Result

A ```requests.exceptions.ConnectionError: [Errno 32] Broken pipe``` error is raised instead.

## Reproduction Steps

A minimal server using flask is given below:

```
#!/usr/bin/env python3

import sys

from flask import Flask, request
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/post_endpoint', methods=['POST'])
def post_normal_response():
    for line in request.stream:
        str_line = line.decode('utf-8')
        sys.stdout.write(str_line)
        sys.stdout.flush()
    return 'OK'

if __name__ == '__main__':
    app.run()
```

Client code illustrating the problem is:

```
#!/usr/bin/env python3

from time import sleep

import requests


VALID_URL = 'http://127.0.0.1:5000/post_endpoint'
INVALID_URL = 'http://127.0.0.1:5000/does_not_exist'


LINES = ['Line {}\n'.format(x) for x in range(5)]
DATA = ''.join(LINES).encode('utf-8') 

def chunked():
    for line in LINES:
       sleep(1)
       yield line.encode('utf-8') 

def test_url(url):
    r = requests.post(url, data=DATA)
    print(r)


    r = requests.post(url, data=chunked())
    print(r)

if __name__ == '__main__':
   test_url(VALID_URL)
   print('-----')
   test_url(INVALID_URL)
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.5.2"
  },
  "platform": {
    "release": "4.4.0-104-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "1000207f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": false
}
```

## Patch to address the issue

[requests-patch.zip](https://github.com/requests/requests/files/1602607/requests-patch.zip)



Thanks for this! Instead of submitting the patch as a zip, consider submitting a Pull Request and linking it to this issue. :)

Pull request done.  If the approach is okay I can look at adding tests etc.

Chunked requests are now handled by urllib3.
Download file with Chinese charactor, the Response headers filename is incorrect, not cn, but messy code. 

When I log infos,
logging.debug("@@@###:%s" % response.headers)
The output is as below:
@@@###:{'Server': 'openresty', 'Date': 'Tue, 02 Jan 2018 03:02:52 GMT', 'Content-Type': 'application/octet-stream;charset=utf8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Content-Disposition': ';filename="æµ\x8bè¯\x95ç\x8e¯å¢\x83ä¿¡æ\x81¯.xlsx"', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'}
U can see the filename is messy.

Please provide us with the output of

```
python -m requests.help
```

If that is unavailable on your version of Requests please provide some basic information about your system (Python version, operating system, etc).
fragment not append on redirect

In the following case (see detailed explanation and test case at http://www.webdbg.com/test/redir/fragment/):
- try to open a link that contains a fragment (say http://foo/#SomeInfo)
- the server sends a 302 Redir to http://bar

## Expected Result

The expected result is that requests library follows the redirection and appends the original fragment from the link (e.g. it redirects to http://bar/#SomeInfo)

## Actual Result

The redirect link is followed without the fragment (e.g. requests tries to open http://bar)

## Reproduction Steps

```python
import requests
response = requests.get("https://www.bayden.com/test/redir/fragment/redir-1.asp#/HereIsSomeInfo")
html = response.text
print(response.url)
```
output is "http://www.enhanceie.com/test/redir/fragment/final.asp"
output should be "http://www.enhanceie.com/test/redir/fragment/final.asp#HereIsSomeInfo"

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.2"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.22"
  },
  "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).

This isn't how redirects work. The RFCs (3986, 7230, 7231, 7232, 7233, 7234, 7235) do not require or prescribe retaining the fragment. If you want us to retain the fragment you'll need to handle redirects yourself. The server is telling us what to redirect to and we're supposed to follow that.

Thanks for opening this issue to clarify.

Actually this was formalized in the rewrite of HTTP/1.1 (see also https://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects)

This is a fantastic way to leak some data to an untrusted server, however, and is probably far from ideal. Oh well, we'll have to fix this.

In case that StackOverflow question goes away, here's the relevant portion of 7231: https://tools.ietf.org/html/rfc7231#section-7.1.2

This should be resolved on master with #4452 and available in the next release. Thanks again for the report @stcioc!
Reduce overall memory usage by removing cgi dependency and writing a protected function

In response to issue #4313 , I removed the cgi module import and added a parse_header function nested inside get_encoding_from_headers in utils.py.  I have run the tests both before and after making these changes.  The test_util cases all passed before and they still do now.  Please let me know about any suggestions to this code.  

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

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

```diff
@@            Coverage Diff             @@
##           master    #4442      +/-   ##
==========================================
+ Coverage      89%   90.14%   +1.14%     
==========================================
  Files          18       15       -3     
  Lines        2065     1543     -522     
==========================================
- Hits         1838     1391     -447     
+ Misses        227      152      -75
```


| [Impacted Files](https://codecov.io/gh/requests/requests/pull/4442?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [requests/compat.py](https://codecov.io/gh/requests/requests/pull/4442/diff?src=pr&el=tree#diff-cmVxdWVzdHMvY29tcGF0LnB5) | | |
| [tests/testserver/\_\_init\_\_.py](https://codecov.io/gh/requests/requests/pull/4442/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdHNlcnZlci9fX2luaXRfXy5weQ==) | | |
| [requests/models.py](https://codecov.io/gh/requests/requests/pull/4442/diff?src=pr&el=tree#diff-cmVxdWVzdHMvbW9kZWxzLnB5) | `93.67% <0%> (+0.22%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/requests/requests/pull/4442?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/requests/requests/pull/4442?src=pr&el=footer). Last update [24092b1...19cfec2](https://codecov.io/gh/requests/requests/pull/4442?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


@sigmavirus24 Thoughts on this?  I figured since the since we are only worrying about parsing content-type headers, we should focus the function on that format.  

@sigmavirus24 Ok, I pushed some changes with your suggestions, it's looking better for sure. 

@SethMichaelLarson Good suggestions, I pushed some changes.  

Besides my two last comments this looks good to me. I'll leave this review for @sigmavirus24 now. :)
  

Thanks for your patience @DemetriosBairaktaris ! This looks excellent!
README does not render properly on PyPI

# Summary

Requests PyPI page does not render, making it much less useful.

## Expected Result

Rendered RST to be shown on https://pypi.python.org/pypi/requests

## Actual Result

Raw unrendered RST:

```
Requests: HTTP for Humans
=========================

.. image:: https://img.shields.io/pypi/v/requests.svg
:target: https://pypi.python.org/pypi/requests

.. image:: https://img.shields.io/pypi/l/requests.svg
:target: https://pypi.python.org/pypi/requests
```

Could this be due to some invalid RST associated with line 110 of README.rst? I think it needs back-quotes, e.g.

``.. _`Contributor Friendly`: https://github.com/requests/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open``

instead of the current:

``.. _Contributor Friendly: https://github.com/requests/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open``

@alexdarling that shouldn't be the problem. In fact our readme check is passing on CI. I suspect whatever the issue *was* is now fixed.

will be fixed in the next release — pypi doesn't allow you to update existing releases any longer!
Proxy doesn't work for https connections

Summary.
The requests proxies do work for the **http** connections but not for **https** connections. I tried to find a solution to this problem but could not find any satisfied answer. Here is the sample test code:

```python
import requests

proxy = {
'http': 'http://user:pass@ip:http-port',
'https': 'http://user:pass@ip:https-port'
}

res = requests.get('https://somesite', proxies=proxy)
print(res.text)
```
## Expected Result
It should return the page content by establishing a connection as it does in case of **http** request.

## Actual Result
I got this error upon using https request:

```bash
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com', port=
443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to
proxy.', error('Invalid response from tunnel request',)))
```
## Reproduction Steps

```python
import requests

proxy = {
'http': 'http://user:pass@ip:http-port',
'https': 'http://user:pass@ip:https-port'
}

res = requests.get('https://somesite', proxies=proxy)
print(res.text)
```

## System Information
I'm using this code on **Windows Operating System**.

It seems to work now, my bad !
Just found the solution here [Socks Support](https://github.com/requests/requests/pull/478)

+1 requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: /search?source=hp&ei=h45CXayCH_eVr7wPmoahuAU&q=inurl:id=1 (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, '远程主机强迫关闭了一个
现有的连接。', None, 10054, None)))
Fix broken link to Certifi

certifi.io doesn't available at least since 07.11.2017
(https://github.com/certifi/certifi.io/issues/16)

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

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

```diff
@@           Coverage Diff           @@
##           master    #4439   +/-   ##
=======================================
  Coverage   90.14%   90.14%           
=======================================
  Files          15       15           
  Lines        1543     1543           
=======================================
  Hits         1391     1391           
  Misses        152      152
```



------

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


@nkonin, would you mind rebasing this onto the current master branch? I think we should be set after that.
requests Read timed out when handle two same header in http response

I use requests's get method to request a url,I found It always timeout,I use wireshark capture the response, the server has response the data,but why requests's get method timeout?,the response as flows
```
GET /onvif/device_service HTTP/1.1
Host: 50.250.78.211
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.18.4

HTTP/1.1 401 Unauthorized
Date: Tue, 26 Dec 2017 03:24:12 GMT
Server: DNVRS-Webs
Cache-Control: no-cache
Content-Type: text/html
Connection: keep-alive
Keep-Alive: timeout=60, max=99
WWW-Authenticate: Digest realm="DVRNVRDVS", domain="::", qop="auth", nonce="6f43ba833ff06ae8b7b36bd2dfb9704c:1514258652870", opaque="", algorithm="MD5", stale="FALSE"
WWW-Authenticate: Basic realm="DVRNVRDVS"

```
test urls:http://50.250.78.211/onvif/device_service

Hi there! Thanks for opening this issue. Unfortunately, it seems this is a request for help instead of a report of a defect in the project. Please use [StackOverflow](https://stackoverflow.com) for general usage questions instead and only report defects here.

---

I would point out that my browser and cURL both exhibit the same behaviour as requests. The reason is that the server doesn't provide a `Content-Length` header to indicate there is no actual body. As a result, all 3 user agents expect a body that is sent as a chunked response (i.e., as if the server had sent `Transfer-Encoding: chunked` as a header). As a result, Requests waits for any data to come and we eventually timeout.
request blocked when i try to request an offline server

i wrote a program with requests to wake up my site.
when i deploy my site,the server can't response.
then i saw the requests blocked forever , can't continue next requst again.
i have no log,just an appearance

Please provide us with the output of

```
python -m requests.help
```

If that is unavailable on your version of Requests please provide some basic information about your system (Python version, operating system, etc).
iOS issue 'No child processes'

I am using Kodi and got the following error. Could you advise me how to solve the issue?

System: iOS 9.3.3 | Kodi 17.6 (arm64)

File "/var/mobile/Library/Preferences/Kodi/addons/script.module.requests/lib/requests/__init__.py", line 97, in <module>
from . import utils
File "/var/mobile/Library/Preferences/Kodi/addons/script.module.requests/lib/requests/utils.py", line 42, in <module>
if platform.system() == 'Windows':
File "/Users/Shared/jenkins/workspace/IOS-ARM64/tools/depends/xbmc-depends/iphoneos8.1_arm64-target/lib/python2.7/platform.py", line 1263, in system
File "/Users/Shared/jenkins/workspace/IOS-ARM64/tools/depends/xbmc-depends/iphoneos8.1_arm64-target/lib/python2.7/platform.py", line 1230, in uname
File "/Users/Shared/jenkins/workspace/IOS-ARM64/tools/depends/xbmc-depends/iphoneos8.1_arm64-target/lib/python2.7/platform.py", line 965, in _syscmd_uname
IOError: (10, 'No child processes')

This is an odd error. At the moment we're not compatible with iOS and that was never really a target that we defined as wanting to be compatible with. It seems that Kodi doesn't allow python to spawn subprocesses in order to determine the system name. As such, when we try to make decisions based on the Operating System, we fail out. I don't think there's presently an ideal way of fixing this.

I tried some approaches from here: https://www.bountysource.com/issues/51501895-kodi-17-5-ios-2-18-4-failing-for-youtube-addon

I can open the broken Addon 'Backup' immediately after installing:
1- Release v2.13.0
2- Release v2.18.4 with replaced code [if platform.system() == 'Windows'] to [if 'win32' in sys.platform]

Restart Kodi leads to a crash. Therefore I need to delete the folder [script.module.requests] manually to use Kodi again. So these are only temporary solutions.

Is that a possible fix to make decisions based on the Operating System?
https://github.com/analogue/mythbox/blob/master/resources/src/mythbox/platform.py#L31

I believe we previously used `'win32' in sys.platform` and it led to unexpected and wildly undesirable side-effects which is why we switched to `platform.system()`. I would need to double-check, but again, since we can't test on Kodi we can't properly support it and it's highly likely this will just regress again.

I finally changed `sys.platform == 'win32'` to `xbmc.getCondVisibility('sys.platform.windows')` in the current 'branch: master'.
---
https://trac.kodi.tv/ticket/12098
http://kodi.wiki/view/List_of_boolean_conditions
How to use this library and Android for picture transmission

Summary.

## Expected Result

What you expected.

## Actual Result

What happened instead.

## Reproduction Steps

```python
import requests

```

## System Information

    $ python -m requests.help

```
<paste here>
```

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).

 What do you mean by 'picture transmission'?

This is not a forum for questions and answers. The place to ask questions for technical help is [StackOverflow](https://stackoverflow.com). Please redirect your discussion there.
Just a question

How i can avoid url encoding into a post parameter?
like:
username=not encoded data&password=not encoded data&login=True

i tried with:
`config={'encode_uri': False}`
but it doen't work anymore

Why don't you want the parameter to be URL encoded? Every server should be able to decode this.

This is not a forum for questions and answers. The place to ask questions for technical help is [StackOverflow](https://stackoverflow.com). Please redirect your discussion there.
Requests shouldn't send IP Address as SNI.

Summary.
According to  RFC 6066, https://tools.ietf.org/html/rfc6066#section-3,
` Literal IPv4 and IPv6 addresses are not permitted in "HostName".`

However, when I send requests like resp = s.get('https://192.168.1.140', verify=False), requests will put 192.168.1.140 in SNI. 

## Expected Result
Not send SNI when URL are based on literal IP address.

## Actual Result
In wireshark, I saw the IP address was put in SNI.

## Reproduction Steps
1. Prepare a HTTPS server at port 4443.
2. Use tcpdump `sudo tcpdump -X -S -s 0 -i lo -w wireshark.log` to capture the packets. 
4. Use below script
```python
import requests
s = requests.Session()
resp = s.get('https://127.0.0.1:4443', verify=False)
```
5. Load wireshare.log to wireshark. You will see the SNI is in SSL request. 

Please let me know if need more info.

Thanks

I am trying to build a test https server following the guide in https://anvileight.uk/blog/2016/03/20/simple-http-server-with-python/. For now, I haven't succeeded. 

You can try to run below Python script and capture network packets using tcpdump.
The IP Address 140.211.11.105 is got from apache.org. I am not sure if it will work for you.
```
C:\windows\system32>ping apache.org

Pinging apache.org [140.211.11.105] with 32 bytes of data:
...

```

```python
import requests
s = requests.Session()
url = 'https://140.211.11.105'
resp = s.get(url, verify=False)
print(resp.url)
print(resp.request.url)
print(resp.content)
````

Then I got below result in wireshark:
![sni_ip_address](https://user-images.githubusercontent.com/4143339/34105809-bdd5222e-e430-11e7-9aa7-77d61df768c6.png)


Closed it. It should be a urllib3 bug. https://github.com/shazow/urllib3/issues/1298
Cookies lost during multiple redirects

Cookies are lost when set by sites returning redirects.

Example:
r=requests.get('http://hostA/url1')
where url gives multiple redirects, possibly multiple sites.
e.g. hostA/url1 -> 302 -> hostB/url2 -> 302 -> HostC/url3

Expectation: 
r.cookies would have all the cookies set by hostA, hostB, and hostC

Actual Result:
r.cookies contains only the cookies set by the hostC. The others are lost. 


Further example from real-world scenario:
$ python3
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r=requests.get('redactedurl')
>>> r.history
[<Response [302]>, <Response [302]>, <Response [302]>, <Response [302]>]
>>> len(r.cookies)
1
>>> 

-----

>>> r=requests.get('redactedurl', allow_redirects=False)
>>> r.cookies
<RequestsCookieJar[]>
>>> c=r.cookies
>>> r.status_code
302
>>> r=requests.get(r.headers.get('location'), allow_redirects=False, cookies=c)
>>> r.status_code
302
>>> c.update(r.cookies)
>>> r=requests.get(r.headers.get('location'), allow_redirects=False, cookies=c)
...
>>> r.status_code
200
>>> c.update(r.cookies)
>>> len(c)
3

## System Information
```
$ python3 -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.1.4"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.1"
  },
  "platform": {
    "release": "17.3.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "1010007f",
    "version": "17.5.0"
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}
```


`r.cookies` contains only the cookies set by the most recent response. Use a `Session` and collect the cookies from `Session.cookies`.
What's the meaning of the homepage image?

What's the meaning of this:
![68747470733a2f2f6661726d352e737461746963666c69636b722e636f6d2f343331372f33353139383338363337345f313933396166336465365f6b5f642e6a7067](https://user-images.githubusercontent.com/16239566/34022048-f8ea84be-e177-11e7-863b-c8ee5f79fab4.jpeg)


A butterfly at the waterline?

Hey @lightning-zgc, the photos you see throughout the Requests docs are taken by Kenneth Reitz. You'll find things like this in most of the documentation for projects he started, and it's mostly there for aesthetic purposes. Hopefully that helps answer your question!

For future reference, we prefer to keep the issue tracker limited to tickets around defects in Requests. Email or social media may be a better avenue for questions like these.
Use hostname not netloc

Fixes #4275 and fixes #4158 by passing only the hostname/IP to urllib's `proxy_bypass` function which was timing out further down in `socket.gethostbyname` when passed a hostname or IP that contained authentication credentials.

While fixing the parameter passed to `proxy_bypass`, I also took the chance to replace other uses of `netloc` with `hostname` in the `should_bypass_function`. 

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

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

```diff
@@           Coverage Diff           @@
##           master    #4427   +/-   ##
=======================================
  Coverage   90.14%   90.14%           
=======================================
  Files          15       15           
  Lines        1543     1543           
=======================================
  Hits         1391     1391           
  Misses        152      152
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/requests/requests/pull/4427?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/requests/requests/pull/4427?src=pr&el=footer). Last update [020f965...2255c34](https://codecov.io/gh/requests/requests/pull/4427?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


@nateprewitt Thanks for the review! Below I've listed the changes I made before I squashed my commits.

- Check if the port exists before adding it to prevent `host:None`.
- Use `{0}` to support Python 2.6.
- Updated the HISTORY.rst.

@ddormer Can you rebase this so it's up-to-date with master? 

@sigmavirus24 Thanks for reviewing this, I've rebased so it's up to date with master.
Making a post to a server on localhost is slow

Question posted here:  https://stackoverflow.com/questions/47766158/why-is-python-requests-to-localhost-slow

Basically I have a trival server running locally.  When I use requests to do a post to it it takes a few seconds to respond.

## Expected Result

A sub-second response

## Actual Result

A pause of a few seconds before a response

## Reproduction Steps

See code shared on https://stackoverflow.com/questions/47766158/why-is-python-requests-to-localhost-slow

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "1.8.1"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.10"
  },
  "platform": {
    "release": "17.2.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "1010005f",
    "version": "17.0.0"
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "20000000"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}
```

Ah nevermind.  Issue resolved instantly.  Got to love Stackoverflow.

I want to know why this happens.
Can anyone help?

I was able to make a **100x** speedup changing `"localhost"` to `"127.0.0.1"`.

@cprogrammer1994 we use DNS in the case when we're not given an IP Address. localhost is plenty fast for me, but my `/etc/hosts` isn't a disaster as was described in the StackOverflow comment above. I suggest you read that question and perhaps fix up your developer environment.

@sigmavirus24 thanks for the fast reply! My hosts file contains a single row (I am on windows). Unfortunately I have a lot of virtual network interfaces that could cause the problem.

- Running `ptime nslookup localhost` takes `0.05` to `0.15` seconds
- It takes exactly 1 second to run a `request.get(...)` using `"localhost"`

It is clearly not a `requests` bug!

The following snippet is slow too:

```py
import urllib.request
urllib.request.urlopen('http://localhost:80').read()
```
urllib3 Which file is in it  ThankYou

Summary.

## Expected Result

What you expected.

## Actual Result

What happened instead.

## Reproduction Steps

```python
import requests

```

## System Information

    $ python -m requests.help

```
<paste here>
```

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).
headers not retained when a custom authentication method is used with request.session

## standard request
```python
r = requests.post(url, auth=JWTAuth('token'), timeout=self.connect_timeout, verify=self.sslcheck, proxies=self.proxies)
```
## standard request headers on server side
```
Host: 127.0.0.1:5000
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.18.4
Content-Length: 39
Content-Type: application/json
```
## session request
```python
self.session.auth = JWTAuth('token')
r = self.session.post(url, json=json, allow_redirects=False, stream=False, timeout=(self.connect_timeout, read_timeout))
```
## session request headers on server side
```
Host: 127.0.0.1:5000
Accept-Encoding: identity
Content-Length: 81
Authorization: Bearer ....
```
In this case no headers are kept
```
{
  "chardet": {
    "version": "3.0.4"
  }, 
  "cryptography": {
    "version": ""
  }, 
  "idna": {
    "version": "2.6"
  }, 
  "implementation": {
    "name": "CPython", 
    "version": "2.7.10"
  }, 
  "platform": {
    "release": "16.7.0", 
    "system": "Darwin"
  }, 
  "pyOpenSSL": {
    "openssl_version": "", 
    "version": null
  }, 
  "requests": {
    "version": "2.18.4"
  }, 
  "system_ssl": {
    "version": "9081df"
  }, 
  "urllib3": {
    "version": "1.22"
  }, 
  "using_pyopenssl": false
}
```

After a little more digging ... 
When custom authentification is used with session, no headers is kept.
```python
class JWTAuth(AuthBase):
    """Attaches HTTP Pizza Authentication to the given Request object."""
    def __init__(self, token):
        # setup any auth-related data here
        self.token = token

    def __call__(self, r):
        # modify and return the request
        r.headers = {'Authorization': 'Bearer %s' % self.token}
        return r
```
```python
self.session = requests.session()
self.session.auth = JWTAuth('token')
```

@johaven your custom authentication class is replacing all existing headers with a single `Authorization` header. You'll need to change the code to call something like `r.headers['Authorization'] = 'Bearer %s' % self.token` or use the dictonary's `update` method. You can use our documentation on custom auth [here](http://docs.python-requests.org/en/master/user/advanced/#custom-authentication).

Since this isn't a defect in Requests, I'm going to close this out.

Indeed, I do not pay attention to the fact that in the example all the headers are overwritten by the authorization.
Thank you for your answer.
requests.exceptions.ProxyError: HTTPSConnectionPool: Failed to establish a new connection

Last week I started exploring requests library for invoking REST APIs, it was working fine, I was able to make calls as expected but today when I run the same python script, it fails with below error. Please help. 

My OS: Ubuntu 16.04
Python: Python 2.7.12
requests library version: 2.18.1


Traceback (most recent call last):
  File "restfilters.py", line 15, in <module>
    vcsession = vcrest.get_vc_session(vcip,"Administrator","password")
  File "/home/vmware/vcrest.py", line 19, in get_vc_session
    s.post('https://'+vcip+'/rest/com/vmware/cis/session',auth=(username,password))
  File "/home/vmware/.local/lib/python2.7/site-packages/requests/sessions.py", line 549, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/vmware/.local/lib/python2.7/site-packages/requests/sessions.py", line 502, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/vmware/.local/lib/python2.7/site-packages/requests/sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "/home/vmware/.local/lib/python2.7/site-packages/requests/adapters.py", line 502, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='10.192.64.32', port=443): Max retries exceeded with url: /rest/com/vmware/cis/session (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fa16ac2c7d0>: Failed to establish a new connection: [Errno 113] No route to host',)))


We literally cannot connect to the proxy you've configured. It's unreachable. This is a network configuration error, not a requests error.

Ok @sigmavirus24 ,  I did check network connectivity between the server I am invoking the REST API and the VM from where I am running python script, it was pinging fine but it is giving same error as reported. I am not getting how to go ahead for troubleshooting this further. Earlier same setup worked fine. Any help would be really appreciated. 

@vThinkBeyondVM The problem exists in that there is a proxy sitting somewhere between Requests and the server you wish to connect to. We cannot connect to the proxy. You have configured the proxy. If you need help debugging that further, please ask your specific questions on [StackOverflow](https://stackoverflow.com/questions/tagged/python-requests) since this is not a defect (or bug) in Requests.

raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.instagram.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetErr
Add a new argument to a request that allows people to always keep the same method after a redirect

Hi, i'm sorry if this is written incorrectly - unsure if feature requests are really allowed, so if they're not just simply delete the issue.

A small annoyance i've found which isn't a problem specifically with requests is when a webserver uses a 302/301 redirect when they should be using a 307 or a 308. This happens a lot with common webservers as more and more websites have http -> https redirects.

This can be a problem when doing anything that isn't a GET request, as request's resolve_redirects code will change the request method when the webserver isn't using the correct http status code (or is trying to preserver backwards compatibility.

My suggestion is to add an argument to a request that allows people to not rebuild the method in the case of redirects.

I have written the code (and test) for it if anybody is interested to look at it.




Thanks, but Requests isn’t accepting additional keyword arguments at this time. Disabling redirect resolution or overriding some of the methods on `Session` that handle redirects can get you what you want. 

I do know it's fixable via disabling redirect resolution, it's just a bit of a pain to work with. 

Thanks though, wasn't sure what was allowed to be added and what wasn't..