Raibek/requests-github-issues huggingface dataset:
ssl handshake fail for timing out

My sample is this:

import requests
host = "https://api.kucoin.com/api/v1/market/candles?symbol=BTC-USDT&type=1min"
r = requests.request('GET', host, timeout=30)
print(r.json())

I expect that the candle data would be returned as json. While I got this each time:

Traceback (most recent call last):
  File "C:\Users\xxxxx\AppData\Roaming\Python\Python37\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\xxxxx\AppData\Roaming\Python\Python37\site-packages\urllib3\connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "C:\Users\xxxxx\AppData\Roaming\Python\Python37\site-packages\urllib3\util\retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.kucoin.com', port=443): Max retries exceeded with url: /api/v1/market/candles?symbol=BTC-USDT&type=1min (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1074: The handshake operation timed out')))

While if I use:

import urllib.request
web = 'https://api.kucoin.com/api/v1/market/candles?symbol=BTC-USDT&type=1min'
req = urllib.request.Request(web)
data = urllib.request.urlopen(req).read().decode("utf-8",'ignore')
print(data)

I could get these candle data (time is about 10 seconds, if you wonder).

This web site could be open and returned data on chrome or with urllib. Since the market data could NOT need the auth parts. I wonder why I got this for requests. Same issues happened for me on website: https://api.bybit.com/spot/quote/v1/kline?symbol=ETHUSDT&interval=1m





You have a proxy configured, ostensibly in your environment, that we can't connect to. It's in your exception message.

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.
How to prevent requests from encoding a comma?

Please refer to our [Stack Overflow tag](https://stackoverflow.com/questions/tagged/python-requests) for guidance.
I have an API which uses comma separated string `'en,fr'` for english and france for example. Requests encode this comma to `%2C` and response failes.
Is there some way to escape encoding of comma, or mark it as safe to use unchanged?

Please refer to our [Stack Overflow tag](https://stackoverflow.com/questions/tagged/python-requests) for guidance.

Alternatively, refer to our [documentation](https://docs.python-requests.org/en/latest/user/advanced/?highlight=prepared%20request#prepared-requests)
Skip the test requiring trustme when it is not available

Modify the nosan_server fixture to cause test_https_warnings to be
skipped when trustme is not installed on the system, rather than causing
the whole test suite to fail unconditionally.  This makes it possible
to run all the remaining tests on systems where trustme cannot be
installed due to its dependencies.

If one cannot install `idna` or `cryptography`, I suspect there are bigger issues that will prevent requests from working as securely or reliably as users expect. I'm not inclined to skip this test and give those users a false sense of security.

Don't requests work well with the Python stdlib OpenSSL support? My grep-foo may be weak here but I don't really see any actual code referencing cryptography (besides some version check and info), and idna doesn't seem to require cryptography.

In other words, I can't find anything requiring it but this one test.

_Right now_ we only use the standard library. That isn't a guarantee going into the future. Generally speaking, architectures that can't install cryptography seem to have limited security support in general. That is a good indicator that use of relatively modern cipher suites won't continue to work and our tests passing on those platforms and architectures are going to end up being a lie. 

Also, this project doesn't claim to support those architectures or platforms meaning we don't need to skip tests on them because we can't even test easily on them. `alpha, hppa, ia64, m68k, s390 (not -x)` are highly niche architectures, we don't skip tests for downstreams because they attempt to support more than we can reasonably support.

Would it work for you if I changed the PR to just move the `import` inside the fixture, so that we would be able to skip that test via command-line without changing the default test suite behavior?

@mgorny that would work

Ok, done! I've added a comment to explain why it's not in global scope.
Response hook does not accept user supplied arguments

Currently response hook does not accept any user supplied arguments. The keyword argument supplied to response hook is a dict of fixed keys generated by `Session.request()`:

https://github.com/psf/requests/blob/590350f8d094c216051510ed1dd18fe871b53b72/requests/sessions.py#L537-L544

It would be more versatile if user supplied data can be made available to response hooks, without resorting to global variables or subclassing (both Session and HTTPAdapter), only because method signatures don't have `**kwargs`. 

About use cases... for example, validation on request body/file is done before sending request, and response hook behaves differently according to such validation result. It doesn't make sense to repeat such validation again from within response hooks, especially when it is expensive.

I can try working on a PR if it's desirable.

## System Information

```json
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.7"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.3"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.12"
  },
  "platform": {
    "release": "7",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "101010cf"
  },
  "urllib3": {
    "version": "1.26.7"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
```


Quoting https://github.com/psf/requests/blob/main/.github/ISSUE_TEMPLATE/Feature_request.md

> Requests is not accepting feature requests at this time.
url "schema" should be "scheme"

https://github.com/psf/requests/blob/590350f8d094c216051510ed1dd18fe871b53b72/requests/models.py#L388-L392

I don't believe the first part of a URL is ever called a "schema." Exceptions and error messages referring to an incorrect schema are confusing, especially in contexts where actual schema errors are possible. If it isn't possible to change the `MissingSchema` exception (it looks like it is slated to be fixed in 3.x) please consider at least changing the error message.

References:
https://www.w3.org/Addressing/URL/url-spec.txt
https://github.com/psf/requests/issues/4495

Hi @DanLipsitt,

We agree the minomer isn't great and did address this in #2961 as you've noted. I'm open to reviewing a PR, although that too has an argument for whether it's "breaking". I'm not sure how the other maintainers feel on the subject.


There's a backwards compatible way to change the exception class that's not great. The message is definitely safe to change though
Update docs with for passing an array as a param

When passing an array for a `GET` request, some servers expect the key to be suffixed with a `[]`
to parse the URL correctly. Adding a note in the documentation for this case.

Further, Is it a good idea to make this behavior a default one? Concatenate a `[]` to the end of all keys
whose value is an array. Would love to hear your thoughts!

> When passing an array for a `GET` request, some servers expect the key to be suffixed with a `[]`
> to parse the URL correctly. Adding a note in the documentation for this case.

We can't and won't document every non-standard edge case that exists. We expect users to understand the services they're talking to and cater to them directly.



> Further, Is it a good idea to make this behavior a default one?

No. It's not a good idea to change behaviour in completely backwards incompatible ways
Update sessions.py

This change will make the hierarchy request **kwargs -> Session args -> environment to be respected. This also solves problems with pip as discussed [here](https://github.com/pypa/pip/issues/9691#issuecomment-791608247)  and  #5735

Read #5735 more closely please. There are certainly people who are unknowingly relying on this behaviour in 2.x and we cannot break them suddenly. It's worse because even if we document this they will still be surprised as they likely have no understanding that they're affected

@sigmavirus24 Thank you for the comment but I disagree this is a wanted behavior. The current status of Session breaks the usage of pip when behind a proxy and the change I proposed is not the same as in #5735. My change keeps the hierarchy the way it should be as already mentioned in the documentation.

The biggest problem right now is that when you use 

 `pip install package --proxy=http\\:proxy_url` 

The way they inject proxy to request is by creating a session object and setting the proprety proxies to it:
```
from requests import Request, Session

proxies = { "http"  : http_proxy, "https" : https_proxy}
session = Session()
session.proxies = proxies
session.request(url)
````

The piece of code above doesn't work as expected in many proxy environments, because Request is actually overriding the given proxies by the system proxies and due to changes in urlib3 it doesn't work if you are doing an HTTPS request using an HTTP proxy server. Many developers can't directly change environment proxy. Thus, due to this problem newer versions of pip (> 20.2.x) can't install packages using the proxy. 

I agree that pip could solve that by giving the proxy directly to request like: 

```
from requests import Request, Session

proxies = { "http"  : http_proxy, "https" : https_proxy}
session = Session()
session.proxies = proxies
session.request(url, proxies)
````

Although, since you allow to set proxies like: `session.proxies = proxies` that SHOULD be respected. 
Saying that I don't see how my proposed change would break anything, since I pinpoint the problem of overriding the proxy. I would please ask for careful consideration on this change.

> Thank you for the comment but I disagree this is a wanted behavior.

Never said wanted. I said unknowingly relied upon. An application is working today that very well may break in confusing and unexpected ways after releasing this. The behaviour is wrong, we intend to fix it in a deliberately breaking release when we can dedicate time towards such a development effort. It's not something we can fix in the 2.x release series.

This change has been carefully considered for as long as the original PR has been open.
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

When running a python program, I see the following error: It is only happening sometimes, not sure why.

One thing I found is using requests 2.5.3, fixes this issue - but using latest versions like 2.22.0 throws the above error.

I looked into code difference and found there's no else condition in adapters.py in latest versions of requests (it is present in 2.5.3). It looks like a bug to me. Is that intentional? If so, how can I solve this issue?

This is the error and else condition that's missing:


```
   return session.request(method=method, url=url, **kwargs)
 File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
   resp = self.send(prep, **send_kwargs)
 File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
   r = adapter.send(request, **kwargs)
 File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
   raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
```


```
      else:
         # All is well, return the connection to the pool.
              conn._put_conn(low_conn)
```

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.
requests error


File "/storage/emulated/0/fb-vedio.py", line 3, in <module>
    import  requests
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/requests/__init__.py", line 133, in <module>
    from . import utils
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/requests/utils.py", line 28, in <module>
    from ._internal_utils import to_native_string
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/requests/_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/requests/compat.py", line 63, in <module>
    from http import cookiejar as cookielib
  File "/data/data/com.termux/files/usr/lib/python3.10/http/cookiejar.py", line 32, in <module>
    import copy
  File "/storage/emulated/0/copy.py", line 2, in <module>
    from uncompyle6.main import decompile
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/uncompyle6/__init__.py", line 50, in <module>
    import uncompyle6.semantics.pysource
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/uncompyle6/semantics/pysource.py", line 138, in <module>
    from xdis import iscode, COMPILER_FLAG_BIT
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/xdis/__init__.py", line 48, in <module>
    from xdis.codetype import (
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/xdis/codetype/__init__.py", line 21, in <module>
    from xdis.codetype.code13 import *
  File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/xdis/codetype/code13.py", line 19, in <module>
    from copy import deepcopy
ImportError: cannot import name 'deepcopy' from partially initialized module 'copy' (most likely due to a circular import) (/storage/emulated/0/copy.py)


Hi there @ABIRHOSSAIN10. This is not a defect with Requests, you have a local file overriding the stdlib copy module.
#homedesign

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


I hope i fix this issues
Not getting cookies from `localhost`

Hello,

This is a follow up on https://github.com/psf/requests/issues/4643, which was closed without a fix. The issue is that `requests` does not get cookies from `localhost`. I could reproduce on `2.26.0`.

I'm reposting the POC from https://github.com/psf/requests/issues/4643#issuecomment-744409050, which was added after the issue was closed.
```py
import pytest
import threading
import requests

from tests.testserver.server import Server, consume_socket_content

def test_cookie_set_for_localhost():

    def response_handler(sock):
        consume_socket_content(sock, timeout=0.5)
        host, port = sock.getsockname()
        sock.send(
            b'HTTP/1.1 200 OK\r\n'
            b'Content-Length: 0\r\n'
            b'Set-Cookie: foo=bar;   Max-Age=86400; Domain=localhost; Secure; HttpOnly\r\n\r\n'
            # b'Set-Cookie: foo=bar; Max-Age=86400; Domain=localhost:' + str(port).encode('ascii') + b'; Secure; HttpOnly\r\n\r\n' # does not help
        )

    close_server = threading.Event()
    server = Server(response_handler, wait_to_close_event=close_server)

    with server as (host, port):
        url = 'http://{0}:{1}/'.format(host, port)
        r = requests.get(url)

        assert r.status_code == 200

        print(host, port)

        # Verify we received our expected cookie
        assert r.cookies
        assert r.cookies.get('foo') == 'bar'

        close_server.set()
```

It is unclear how https://github.com/psf/requests/issues/5388 could get them.

I don't think this is actually request's bug. It looks like Python's [CookieJar.extract_cookies](https://docs.python.org/3/library/http.cookiejar.html#http.cookiejar.CookieJar.extract_cookies) doesn't parse them properly.

Ok, this is not a bug, this is a feature: https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain/32210291#32210291

Thanks for looking into the issue.

I doubt it’s a feature or the SoF answer is largely inaccurate since latest version of Chrome/FireFox andSafari stored the cookies on the website I had tested but requests did not.

I've opened a bug report and wrote a possible solution: https://bugs.python.org/issue46075
However, since this is, definitely not a requests bug, this issue should probably be closed

Thank you 👍
Proxy with authentication does not halt after upgrading to latest version

I'm not sure if this is a bug but when I upgraded to 2.26.0 proxy doesn't authenticate or something

The code works fine on 2.6.0 but when I have it on 2.26.0, it doesn't give any output or crash.
One thing that I found was urllib3 version 1.24.3 works fine but 1.26.6 doesn't.

## Expected Result

An output / termination of the program

## Actual Result

Nothing outputs and looks like it runs forever

## Reproduction Steps

```python
import requests

# the proxy with authentication
p = "user:pass@ip:port"

proxy = {
    "http": "http://" + p,
    "https": "https://" + p
}

# any url
url = ""

# this statement doesn't halt
requests.get(url, proxies=proxy)
```

## System Information

    $ python -m requests.help

```json
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.4"
  },
  "cryptography": {
    "version": "3.4.7"
  },
  "idna": {
    "version": "3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.6"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "101010bf",
    "version": "20.0.1"
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "1010107f"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": true,
  "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). -->


Try

```py

proxy = {
    "http": "http://" + p,
    "https": "http://" + p
}
```

See also #5843 and issues linked from there
Possible to use pycryptodome rather than pycrypto 2.6.1?

Requests seems to be installing the dependency pycrypto 2.6.1.

I'd rather use pycryptodome. Is this possible?

Requests doesn't use [pycrypto](https://github.com/psf/requests/blob/main/setup.py#L43) as a dependency. We use "cryptography" indirectly through pyOpenSSL in old versions of Requests. Closing this as N/A.

Thanks @sethmlarson 

It must be coming from somewhere else…

```
root@ba2d298de6ea:/src# cat /tmp/requirements.txt 
requests
root@ba2d298de6ea:/src# pip3 freeze
asn1crypto==0.24.0
certifi==2021.10.8
charset-normalizer==2.0.7
cryptography==2.1.4
idna==2.6
keyring==10.6.0
keyrings.alt==3.0
pycrypto==2.6.1
pygobject==3.26.1
pyxdg==0.25
requests==2.26.0
SecretStorage==2.3.1
six==1.11.0
urllib3==1.26.7
root@ba2d298de6ea:/src# 
```

For anyone else that thought it came from requests...

```
root@ ba2d298de6ea:/src# apt remove python3-crypto
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  python3-crypto python3-keyrings.alt
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 1507 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 33231 files and directories currently installed.)
Removing python3-keyrings.alt (3.0-1) ...
Removing python3-crypto (2.6.1-8ubuntu2) ...
root@ ba2d298de6ea:/src# exit
```
Reusing SSLContext in a session

A pull request to take a hit at fixing issue #4322 

Worked with my team and we made it so that HTTPAdapter has a default SSLContext initialized when the adapter is constructed. SSLContext is made by using urllib3's function to create context. The context is passed into the poolmanager as pool_kwargs which can take in SSLContext.

Tested the reuse of SSLContext by using jmcackle's test functions they've made for adapters.

I believe this ended up addressed in 9a40d1277807f0a4f26c9a37eea8ec90faa8aadc.
Create PULL_REQUEST_TEMPLATE.md

You have issue temaplet but i think you also need a pull request template so i created one oull request template at .github it may help you i commented some of the lines of the pull request template you can remove it from comment to code.

I think it may help you ☺☺

Hi @itsMeShon 

Thanks for sending this but it doesn't fit our needs and the maintainers need to make a decision on what information we actually want in a PR template. We don't have a lot of time right now to discuss that and provide you that feedback, so I'm going to close this.

Welcome! If ypu say what type of template the maintainers need i will help you with that!! ☺☺
Disable url encoding for multipart/form data

curl -F allows to upload multipart for raw data w/o encoding - as bytes
how to disable it for files being sent via `request.post(..., files = files)`?
I know that one can send it with `request.post(...data=data)`, but if you do so, there will be no special `Content-Disposition` and boundaries data, and you should put them on your own, thats not handy at all.

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.

`Unfortunately, it seems this is a request for help instead of a report of a defect in the project`
I tried to find answer there, but seems like requests lib lacks this feature, so in fact his is not only a request for help, but feature request too.

I'm very interested in a clarifacation or a better documentation regarding such cases. I ran into some problems exactly because of this issue.
EDIT:
Found this one: https://franklingu.github.io/programming/2017/10/30/post-multipart-form-data-using-requests/
Cannot prevent requests library from encoding `|`

There are various workarounds to ensure that there is no encoding for certain other characters like `:+`. Some of which involve passing the URL directly. But `|` seems to encoded regardless whether I pass in the url directly or prepare via `prepare_url`.

## Expected Result

```python
base_url = 'https://www.example.com/search?'
query = 'date_range=2017-01-01|2017-03-01'
r = requests.get(base_url + query)
print(r.url)
# output: 'http://www.example.com/search?date_range=2017-01-01|2017-03-01'
```

## Actual Result

```python
base_url = 'https://www.example.com/search?'
query = 'date_range=2017-01-01|2017-03-01'
r = requests.get(base_url + query)
print(r.url)
# output: 'https://www.example.com/search?date_range=2017-01-01%7C2017-03-01'
```

## Reproduction Steps

```python
import requests
base_url = 'https://www.example.com/search?'
query = 'date_range=2017-01-01|2017-03-01'
r = requests.get(base_url + query)
print(r.url)
```
You can try substituting `www.example.com` for a domain/website you own in order see what can happen from the web backend.

## System Information

    $ python -m requests.help

```json
{
  "chardet": {
    "version": "3.0.4"
  },
  "charset_normalizer": {
    "version": "2.0.7"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.5"
  },
  "platform": {
    "release": "4.4.0-19041-Microsoft",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "1010107f"
  },
  "urllib3": {
    "version": "1.26.5"
  },
  "using_charset_normalizer": false,
  "using_pyopenssl": false
}
```

Hi @alanyee, this should be possible with the [PreparedRequest](https://docs.python-requests.org/en/master/user/advanced/#prepared-requests) workflow. You'll need to update the URL after preparation. I would note what you're doing violates the HTTP spec though and it may be worth reaching out to the service in question to correct the behavior.


```
import requests

base_url = 'https://www.example.com/search'
query = '?date_range=2017-01-01|2017-03-01'

s = requests.Session()
req = requests.Request('GET', base_url)
p = req.prepare()
p.url += query
resp = s.send(p)
print(resp.request.url)
```
what't the equivalance of "curl -T" in requests

I have a torchserver api that recieve image files to generate result. 

I can use the curl command `curl -T "dog[1-6].jpg" http://my-torchserver/address ` to put multiple files to the server and get the right result.

what's the equivalance expression of this curl command using requests?


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.
guess_filename: Use attribute 'filename'  and then try 'name' 

I've created a Flask server that accepts multipart data  (uploaded file) and simply proxy it to another server using Requests .
I found that the upload works perfectly except the fact that Requests loses the filename. The uploaded filename is replaced with the field-name of the of the multipart data.

It seems that in Flask,  multipart  arrive as type `werkzeug.datastructures.FileStorage` . 
The FileStorage instance includes the "name" attribute which is the field-name of the multipart  as well as the "filename" attribute which includes the filename.  

The `requests.utils.guess_filename`  currently using just the `name` attribute to determine (guess) the filename however in order to be compatible with Flask (and possible other libraries) it would probably be better to try first the "filename" attribute.







This works fine for any object that implements the file like object API as it's intended. If there's a problem with flask, that's not our responsibility to paper over here and the files parameter supports overriding the filename so this is unneeded complexity
HTTPS proxies not working with Python's requests module

Summary

We try request module with below code spinet 

Our Proxy srver running on https
```

import requests
url = 'https://google.com'
roxies = {'https': '10.x.x.x:443'}
if __name__ == '__main__':
    print(url)
    print(roxies)
    response = requests.get(url, proxies=roxies)
    if response.status_code == 200:
        print(response.text)
    else:
        print ('Response ERROR', response.status_code)
```
Same connection we tried from curl its working fine.
`   curl -v -x https://10.x.x.x:443 https://google.com
` 


## Expected Result
Request module should connect to proxy server over https

What you expected.

Request module should connect to proxy server over https

## Actual Result

Request module giving following error while connecting to proxy server over https
OSError('Tunnel connection failed: 400 Bad Request')))

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).


 python --version
Python 3.7.7


Hi there,

Thanks for reaching out. Unfortunately, there's too little detail in this issue to be able to help you and it's not reproducible. That indicates a likely problem in your environment which we are not responsible for debugging and which the maintainers of this project do not have the time to help you with. As a result, I'm closing this issue.

In the future, please search **closed and** open issues before creating new ones that are duplicates.
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

I am trying to download 100GB+ files using requests.get. To avoid out of memory, i set stream = True, and read data from response using iter_content。 For example:
![image](https://user-images.githubusercontent.com/63039413/137586862-57b5ab5a-f2b2-4bf4-a3b3-64a6a9e2e707.png)


but i got this error,  requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read)).

How to solve this problem

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.
TypeError: __init__() got an unexpected keyword argument 'strict'

Request generates error TypeError: __init__() got an unexpected keyword argument 'strict'.

## Problem

This is the line of code that is erroring out:
*connectionpool.py line 560*
```python
connection = VerifiedHTTPSConnection(host=self.host,
                                             port=self.port,
                                             strict=self.strict) # this is error line
```
And this is the `VerifiedHTTPSConnection` class that it is trying to instantiate:
*connectionpool.py line 74*
```python
class VerifiedHTTPSConnection(HTTPSConnection): # class that is being instantiated
```

The problem is the `strict` parameter being passed through.
According to the [HTTPSConnection docs](https://docs.python.org/3/library/http.client.html#http.client.HTTPSConnection):

> class http.client.HTTPSConnection(host, port=None, key_file=None, cert_file=None, [timeout, ]source_address=None, *, context=None, check_hostname=None, blocksize=8192)
> ...
> Changed in version 3.4: The strict parameter was removed. HTTP 0.9-style “Simple Responses” are no longer supported.

Removing `strict=self.strict` fixes the error, but is not a long-term solution.

## Reproduction Steps

```python
import requests
requests.get(url='https://httpbin.org/get')
```


## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": "3.4.7"
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "101010bf",
    "version": "20.0.1"
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.4"
  },
  "using_pyopenssl": true
}
```


I am using conda as opposed to pip, wondering if that would make a difference?

**Cause of problem: [xmla package](https://pypi.org/project/xmla/) forcing requests to install lower version**

After running
```bash
pip uninstall requests
conda uninstall requests
pip install requests=2.26.0
```
The following error was shown
```bash
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
xmla 0.7.2 requires requests==1.2.3, but you have requests 2.26.0 which is incompatible.
```
I ran
```bash
pip uninstall xmla
```
and all requests work as expected.
Connect Error 10054 Starts Happening Randomly

When using requests it was working fine for about a week, but then it started randomly throwing 10054 errors. At first it was only when I would debug it with VSCode and it would work fine form the terminal. But then it started happening even when running from the terminal.

## Expected Result

Any actual response code and data.

## Actual Result

"ConnectionResetError" was thrown. 

## Reproduction Steps

```python
import requests

print(requests.get("https://google.com"))
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.6"
  },
  "cryptography": {
    "version": "3.4.8"
  },
  "idna": {
    "version": "3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.7"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "101010cf",
    "version": "21.0.0"
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "101010cf"
  },
  "urllib3": {
    "version": "1.26.7"
  },
  "using_charset_normalizer": true,
  "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).

The full error is attached in a .txt file.
[error.txt](https://github.com/psf/requests/files/7333369/error.txt)

Hi @technodragon253,

This isn't an issue with Requests. A 10054 error causing a connection reset is due to either the server or an intermediary in your network forcibly closing the connection. You're either being throttled for abuse or encountering an issue in your network. We'd recommend checking proxies and ensuring you're calling the server responsibly.

You sure? 'Cause everything works fine in IDLE. Also I have tried reinstalling the package.

@nateprewitt Can you reopen the issue?

I would recommend ensuring nothing is intercepting your requests locally. If the issue persists, the best option is to open a question on StackOverflow. We cannot control the actions of an external server and the fact it's inconsistent points to a configuration/environment issue. We can't provide troubleshooting support in this issue tracker.

Okay cool. Thanks for your help!
Post file upload Content-Length always 0

When uploading a file via post, the content-length is always zero, which might cause problems.

## Expected Result
Properly calculate content-length as e. g. `pycurl` does.

## Actual Result
`Header Content-Length 0`

## Reproduction Steps

```python
import requests

heads = { 'Authoriziation': 'Bearer ...'
          'Content-Type': 'multipart/form-data',
          'Accept': 'application/json'
        }

files = { 'file': ('dummpy.pdf', open(filename, 'rb'), 'application/pdf') }
ret = requests.post('https://my.apiendpoint.io/jadajadajada',
          files=files, headers=heads)

```

## System Information

```
$ python3 --version
Python 3.8.10
$ pip3 list|grep requests
requests               2.23.0
```
Best,
Matthias

This works for me. Although, i don't specify the `Content-Type` header because Requests must manage that.

Pleas elet us know if you have additional information about how to reproduce this

Thanks for the hint about leaving out `Content-Type`. Surprisingly to me that works, contradicting the API documentation:

https://developers.lexoffice.io/docs/#vouchers-endpoint-upload-a-file-to-a-voucher

That API documentation is poorly written. `multipart/form-data` requires a boundary. Curl may add it to the header for you (I don't care to verify that theory) but Requests assumes that you know better and doesn't modify it, so it generates the content and your server can't handle it.
Add doc build requirements for RTD

Adding a requirements.txt file under the doc directory to specify our doc generation requirements. The only current requirement is Sphinx>4, for #5954. Once this is merged, this can be wired up to Read The Docs to be used when auto-building changes. We're currently relying on the default which is Sphinx 1.8.2 and missing some more recent features.

FYI @sigmavirus24 this relates back to https://github.com/pypa/twine/pull/810#discussion_r707236656.

@nateprewitt Could y'all enable [Preview Documentation from Pull Requests](https://docs.readthedocs.io/en/stable/pull-requests.html) for RTD? Beyond being an additional helpful check for documentation-oriented PR's, I think it might let me test my projects to see if this change resolves the intersphinx issue.

I don't have access to the project on RTD and I'm thinking that @nateprewitt doesn't either. This certainly won't break things, so we'll merge it since we can't do PR changes

@bhrutledge I'm looking at options to enable the preview builds. This change is probably worth doing regardless. I've enabled building with the new requirements, so the live docs should be set to test.
Change the Repo Description (short) on GitHub

The GitHub repository description (homepage, top left) has a small but noticeable grammatical error.

Currently, it is "A simple, yet elegant HTTP library." However, in the README, you can see the grammatically correct version "A simple, yet elegant, HTTP library."

Please add the comma after "elegant" and save my sanity.

Hi @http-samc, I've updated the description to keep ourselves consistent. I'll preface this by stating I'm not a professional editor, but I'm not certain the original change in the README was "more correct". These are coordinating adjectives, and have no strict requirement to be followed by another comma.

Either way, rest easy, I hope there wasn't too much distress ;)

Thanks! 💯
autodoc type hints and intersphinx aren't working with the `requests` public API

It looks like autodoc is resolving type hints like `requests.Response` to their internal definition, e.g. `requests.models.Response`. This means the intersphinx references to the [Requests API docs](https://docs.python-requests.org/en/latest/api/) don’t work, resulting in build messages like `WARNING: py:class reference target not found: requests.models.Response`.

Originally reported as https://github.com/sphinx-doc/sphinx/issues/9653, but reported here as suggested in https://github.com/sphinx-doc/sphinx/issues/9653#issuecomment-939272975:

> It seems the document of requests was built by Sphinx-1.8.5. So an index entry for `requests.models.Reponse` is not generated. This problem will be resolved by upgrading Sphinx to 4.0 or newer. https://readthedocs.org/projects/requests/builds/14778070/

## Expected Result

It'd be nice if the types for `requests` classes in argument defaults and parameters were linked to the Requests documentation.

## Reproduction Steps

I put an example repo with instructions up at https://github.com/bhrutledge/sphinx-requests-typehints, generated via [sphinx-apidoc](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html). The rendered docs are at https://sphinx-requests-typehints.readthedocs.io/en/latest/example_package.html.

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.5"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.7"
  },
  "platform": {
    "release": "20.6.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "101010cf"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
```


Hi @bhrutledge, it looks like we're just using the versions provided out of the box by RTD. I've put up a PR (#5956) to add a requirements.txt file for the docs using the latest version (4.2.0). It builds fine locally, so it appears fine for us to move.

Closing with #5956

Confirmed that this is working as desired:

https://sphinx-requests-typehints.readthedocs.io/en/latest/example_package.html
https://twine.readthedocs.io/en/latest/internal/twine.commands.upload.html

Thank you!

Good to know :-)
Add ipv6 support to should_bypass_proxies

Add support to should_bypass_proxies to support
IPv6 ipaddresses and CIDRs in no_proxy. Includes
adding IPv6 support to various other helper functions.

Hi @nateprewitt @sethmlarson , is this something you'd consider merging ? 

I'm facing this same issue.  @nateprewitt @sethmlarson Any update on your thoughts?

Running into the same problem with this, it sure would be nice to have the ability to specify IPv6 CIDRs in no_proxy.  What's holding this up?

@nateprewitt @sigmavirus24 @sethmlarson would you have a chance to look at this please, its been hanging around for over 2 years and still causing me problems. 

It'd be nice to have this implemented. Is there any way I can help?

Hi @frenzymadness , if you can review or confirm that this works for your use case then that would be appreciated but
ultimately this PR has been waiting on reviews  from one of the maintainers I'm not sure how best to get it some traction besides pinging them on here.

We are going to test this change internally to get some confidence.

Derek tested the package in OpenShift 4.15 and the functionality proposed here works as expected. Is there any chance to merge this?

During additional testing, my colleague raised an interesting question: Are `::/0` and `0.0.0.0/0` valid values for `no_proxy`? The current implementation for IPv4 does not allow masks to be lower than 1 and the new implementation for IPv6 does the same.

I see a use-case for `::/0` - let's say I have a proxy running on both protocols but I want it to be used only for IPv4 - then it might make sense to use `NO_PROXY` for all IPv6 addresses. What do you think?

What can I do to get this merged? We've reviewed the change and tested it in a real environment with real use cases. Is there anything else we can do?
Requests verify cannot take multiple ssl_ca certs 

Summary.
Like the ```http.client``` library, in which we can use the ```load_verify_locations()``` multiple times for multiple ca certs can be added. The python requests cannot take multiple certs for the ```verify``` parameter

## Expected Result
All the certs should be taken in account for SSL verification.

What you expected - I expected to verify against multiple certs.

## Actual Result

What happened instead -SSL verify failed.

## Reproduction Steps

```python
import requests
crt1 = '/path_to_cert1'
crt2 = 'path_to_cert2'
requests.get(url, verify=crt1)
or requests.get(url, verify=crt2)

# Cannot give both paths somehow.

```

## System Information

    $ python -m requests.help

```
I am using a linux machine.
```
**If this is not supported, is there any way to do that ??**

How is this "Add doc build requirements for RTD # 5956"  related to this issue ?

This is a restriction of urllib3 which only allows configuring TLS on pool creation, not per request. Closing this issue as we can't do anything here.
SSLError - CERTIFICATE_VERIFY_FAILED

## Summary

Started getting SSLError when invoking API using requests module.
SSLError: HTTPSConnectionPool(host='<HOST URL>, port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))

Just to add that this is on RHEL

>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.1e-fips 11 Feb 2013'

The system openssl is 
Version     : 1.0.1e, 
Release     : 58.el6_10

python was built using source.

## Expected Result

Was not expecting an SSLError. This is not a problem with the source website as the same call works fine using postman. Could this have anything to do with letsencryt root certificate expiration?

## Actual Result
SSLError: HTTPSConnectionPool(host='<HOST URL>, port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))

## Reproduction Steps

```
Invoke API using python requests and without verify=False

```

## System Information

Just to add that this is on RHEL

>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.1e-fips 11 Feb 2013'

The system openssl is 
Version     : 1.0.1e, 
Release     : 58.el6_10

python was built using source.

    $ python -m requests.help

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "charset_normalizer": {
    "version": null
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.9"
  },
  "platform": {
    "release": "2.6.32-754.9.1.el6.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "1000105f"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": false,
  "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).

Might be getting hit by LetsEncrypt's old root CA expiring. Try upgrading certifi or whatever certificates you're using on the OS.

Duplicate of https://github.com/certifi/python-certifi/issues/164
RequestsCookieJar._find_on_duplicates wrongly fails on cookie with empty value

Getting the value of  a cookie which is set without a value by a website raises a `KeyError`. I don't know if this is by design. Browsers seem to accept these kind of cookies, even though this behaviour seems like bad practice.

## Expected Result

An empty string.

## Actual Result

`RequestsCookieJar._find_no_duplicates` raises a `KeyError`

## Reproduction Steps
In `ipython`:
```python
import requests
resp = requests.get("https://www.pib-insurance.com/")
resp.cookies.get_dict() # pretty print cookies
resp.cookies["firstname"]
```

## Fix
I think last `if` in `_find_no_duplicates` (line **397** of `cookies.py`) should be `if toReturn is not None:` to accommodate for cookies without values.

Thanks!

Mark，the same problem 

Mark, the same problem