Raibek/requests-github-issues huggingface dataset:
Failed to establish a new connection: [WinError 10060]

Now I have a very difficult problem, I have spent a few days and still have not solved it, I hope to get help ,Thanks.
When I request the google map website, I  use the 'requests.get' method to report an exception. The request code and exception are as follows:
```python (Single thread)
import requests
   header = { 
                  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
                  'Accept': '*/*',
                  'Connection': 'close',
                  'Accept-Encoding': 'gzip, deflate, br',
                  'Accept-Language': 'zh-CN'}
        weburl = 'https://www.google.com.hk/maps/search/hospital/@1.26,103.7,12z'
        response = requests.get(weburl, headers=header, verify=False)

``` Actual Result -->Exception
      HTTPSConnectionPool(host='www.google.com.hk', port=443): Max retries exceeded with url: /maps/search/hospital/@1.26,103.7,12z (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000026D6189A700>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。'))

## Other info
  Currently my computer browser can access thew weburl normally.
  I also changed the parameter weburl value in the code to www.baidu.com, the request can also be successful
 
## System Information

    $ python -m requests.help

{
  "chardet": {
    "version": "4.0.0"
  },
  "charset_normalizer": {
    "version": "2.0.1"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.4"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": false,
  "using_pyopenssl": false
}


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.
Stop abusing pytest-httpbin to test commonName support

pytest-httpbin<1.0 ships with a server certificate with a commonName but
no subjectAltName. urllib3 2.0 will stop supporting those in the future,
so we want to upgrade pytest-httpbin.

Unfortunately, `test_https_warnings` was relying on this broken
certificate. With this change, we use `trustme` to create a broken
certificate specifically for this test, so that we can upgrade
pytest-httpbin and make sure that other tests relying on httpbin TLS
support will continue to work with urllib3 2.0.

Closes #5530

You can see the tests passing in my fork: https://github.com/pquentin/requests/actions/runs/1021954813
v2.26.0

2.26.0 (2021-07-13)
-------------------

**Improvements**

- Requests now supports Brotli compression, if either the `brotli` or
  `brotlicffi` package is installed. (#5783)

- `Session.send` now correctly resolves proxy configurations from both
  the Session and Request. Behavior now matches `Session.request`. (#5681)

**Bugfixes**

- Fixed a race condition in zip extraction when using Requests in parallel
  from zip archive. (#5707)

**Dependencies**

- Instead of `chardet`, use the MIT-licensed `charset_normalizer` for Python3
  to remove license ambiguity for projects bundling requests. If `chardet`
  is already installed on your machine it will be used instead of `charset_normalizer`
  to keep backwards compatibility. (#5797)

  You can also install `chardet` while installing requests by
  specifying `[use_chardet_on_py3]` extra as follows:

    ```shell
    pip install "requests[use_chardet_on_py3]"
    ```
  Note that installation of `chardet` in your environment through any means will disable use
  of `charset_normalizer`.

  Python 2.7 still depends upon the `chardet` module.

- Requests now supports `idna` 3.x on Python 3. `idna` 2.x will continue to
  be used on Python 2 installations. (#5711)

**Deprecations**

- The `requests[security]` extra has been converted to a no-op install.
  PyOpenSSL is no longer the recommended secure option for Requests. (#5867)

- Requests has officially dropped support for Python 3.5. (#5867)


Yep, great call out. I'll get that added.
Disable requests[security] and remove 3.5 support references

## requests[security]

This PR will remove functionality from the `requests[security]` extra. We initially removed default support for PyOpenSSL in Requests 2.24.0 (#5443) as it is now considered less secure. Deprecation of the `extras_require` was announced in [Requests 2.25.0](https://github.com/psf/requests/blob/master/HISTORY.md#2250-2020-11-11) and we're officially removing the `extras_require` functionality in Requests 2.26.0. 

Projects currently using `requests[security]` after this change will continue to operate as if performing a standard requests installation (secure by default).

While not recommended, if PyOpenSSL support is still a requirement in your project, you may install `urllib3[secure]` and add `urllib3.contrib.pyopenssl.inject_into_urllib3()` to your code to re-enable the functionality.

## Python 3.5 Support

We will also be removing support for Python 3.5 in Requests 2.26.0 as announced in the [2.25.0 release notes](https://github.com/psf/requests/blob/master/HISTORY.md#2250-2020-11-11).
How to set requests to use ipv4 by default?

When i tried to use `requests.get("www.google.com")` and it hangs for 3 minutes and then succeed.
after debug i found it connect to ipv6 address first and then tries to ipv4.
So far i use `timeout=3` to force ipv6 try to timeout ASAP. but it's tricky. is there anyway to make it use ipv4 by default?

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.
More Options To Run Example Code

#### Making the example code sample available as a copy and paste and then run in any exiting python file.

Hi @jameskaggwa, thanks for contributing to Requests! Unfortunately, I don't think we'll accept this PR at this time. We expect a basic level of Python knowledge with the docs, so understanding writing code in a file vs in the interpreter is assumed. Otherwise, the docs become significantly bloated and more difficult to find relevant information.
Empty space when using GET

I am trying to use GET to get current code for a project of mine to have an auto update system, but whenever I GET the latest latest code (raw github file) it adds blank lines in between lines of code, for example:
```
def clear():

    os.system('cls' if os.name =='nt' else 'clear')

clear()
```
It is adding unnecessary lines in between everything when their is none in the code. My code is:
```
import requests, time

ask = input('Would you like to update to the latest version of Switchence? ')
if ask == 'y' or ask == 'yes':
	print('Ok, updating...')
	try:
		onlineVersion = requests.get('https://raw.githubusercontent.com/Aethese/Switchence/main/main.py')
		if onlineVersion.status_code != 200:
			print(f'[ERROR] status code is not 200, it is {onlineVersion.status_code}')
			time.sleep(5)
		else:
			onlineVersion = onlineVersion.text
			with open('autoupdate.py', 'w') as file:
				file.write(onlineVersion)
			print('Successfully updated to latest version! Rerun the program to use the newest version!')
		time.sleep(5)
	except Exception as error:
		print(f'Couldn\'t get latest latest update | {error}')
		time.sleep(5)
elif ask == 'n' or ask == 'no':
	print('Ok, you will not update to the latest version')
	time.sleep(5)
else:
	print('The only acceptable answers are Yes or No')
	time.sleep(5)
```
Can someone help me or explain to me why my code won't work? I am running latest pip version of requests.

This question is likely more suited for StackOverflow as there probably isn't a defect in Requests causing your issue. Please reserve this issue tracker for defects in Requests.
http redirection found that the authentication is missing

Summary.

I find a problem , if http is redirected . auth is missing
```python

        if 'Authorization' in headers and self.should_strip_auth(response.request.url, url):
            # If we get redirected to a new host, we should strip out any
            # authentication headers.
            del headers['Authorization']


```

Yes that's on purpose. You can find the reasoning why in our documentation and in our issue tracker
Fix calling get_connection() with a positional argument when it is optional


This says it's fixing something, but it's not strictly necessary and there's no context for why you feel this to be necessary. Can you elaborate?

Oh sorry for the lack of details, it seems I closed my computer without having filled the description...

I subclassed the `HTTPAdapter` class, here is the revelant code: https://github.com/httpie/httpie-snapdsocket/blob/aa0d58beca2475b461ba9eac420fff5583e67bed/httpie_snapdsocket.py#L21
It works like a charm.

But then, I wanted to replace 
```python
def get_connection(self, url, proxies=None):
    # ...
    return super().get_connection(url, proxies=proxies)
```
with 
```python
def get_connection(self, url, **kwargs):
    # ...
    return super().get_connection(url, **kwargs)
```
To be resilient to future API updates on the `requests` side.

It will not work:
```python
Traceback (most recent call last):
  File "httpie-snapdsocket/tests.py", line 17, in test_simple
    res = session.get('snapd:///v2/find?name=' + package).json()
  File ".../site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File ".../requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File ".../site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File ".../site-packages/requests/adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
TypeError: get_connection() takes 2 positional arguments but 3 were given
```

I can live with it though.

> ```python
> def get_connection(self, url, **kwargs):
>     # ...
>     return super().get_connection(url, **kwargs)
> ```

Why not

```python
def get_connection(self, url, proxies=None, **kwargs):
    # ...
    kwargs.setdefault("proxies", proxies)
    return super().get_connection(url, **kwargs)
```

That achieves what you want without making a unnecessary change here

The goal was to not care about `kwargs` at all. So that when/if the `get_connection()` signature changes, my code will still work.

It's incredibly unlikely to change
Fix inconsistent exception type in response.json() method

## Summary
Fixes the inconsistency of errors thrown in the `response.json()` method in `models.py`, while preserving backwards compatibility. 

### What we used to have
Depending on whether or not `simplejson` was installed in the user's library, and whether the user was running Python 3+ versus Python 2, a different exception would get thrown when there was an issue with decoding response text as JSON. If `simplejson` was installed, `simplejson.JSONDecodeError` would get thrown. If not, `json.JSONDecodeError` would get thrown for Python 3+ users, and `ValueError` for Python 2 users. Thus, depending on the scenario, users would find themselves having to catch either `simplejson.JSONDecodeError`, `json.JSONDecodeError`, or `ValueError` in the case of the `response.json()` method failing. This inconsistency is not ideal.

### What we have now
There is now one error class in `exceptions.py` that will represent all errors that can be thrown or caught in the `response.json()` method: `requests.JSONDecodeError`. All `simplejson` functionality was replaced with `json` functionality, but the new error type aliases both `json.JSONDecodeError` and `simplejson.JSONDecodeError`. If `simplejson` is not installed, its `JSONDecodError` is replaced with a plain `Exception` when aliased. If the user is running Python 3+, `json.JSONDecodeError` is aliased, but if the user is running Python 2, that is replaced with `ValueError` when aliased, as the `JSONDecodeError` was not previously a part of the `json` library. Now, all five error types, `json.JSONDecodeError`, `simplejson.JSONDecodeError`, `ValueError`, and `requests.JSONDecodeError` and its parent class `requests.RequestException`, will be caught from the `requests.JSONDecodeError` that will be raised.

Fixes #5794
@sigmavirus24 

Same issues with Python 2 again. Is that normal?

@steveberdy Please refer to my previous comments in the code review. Your current approach isn't going to work in Python 2. I'd recommend using your exception resolution in compat.py to handle this. I think there are also some outstanding comments that are still unresolved.

@sigmavirus24 @nateprewitt I made the necessary edits to fix workflow failures. Any feedback on Python 2 compatibility before running the workflows again? Thanks.

Hi @steveberdy, I'd recommend setting up a testing environment locally with our tox script and something like `pyenv` to manage Python versions. If you're having difficulty with that, you can test changes yourself on another branch using Github actions in your own repository. That will help expedite your testing cycle and avoid needing to ping this thread every time a change is made.

@nateprewitt Thank you for the advice. I ran the workflows, and all tests passed: https://github.com/steveberdy/requests/actions/runs/1023889042

Is this ready to merge?

Let's just commit to the next release being 2.27.0. Heck we can push that out whenever and if we can get the proxy stuff merged too (once it's in a good state) then I think we can cut 2.27 with just these two "features"

Alright, sounds like a plan to me. Thanks again, @steveberdy.
stream=True break the zip file

![image](https://user-images.githubusercontent.com/4510984/124194421-28239880-dafb-11eb-9a6b-132c4e550ead.png)

![image](https://user-images.githubusercontent.com/4510984/124194806-cd3e7100-dafb-11eb-876b-e4de04ae4417.png)

**If I download that file by browser, it can be open.**

## Expected Result
Download file do not break the file.

## Actual Result
File broken, can not open.

## Reproduction Steps

```python
import requests

```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "3.2.1"
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.7.6"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "1010108f",
    "version": "19.1.0"
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "1010108f"
  },
  "urllib3": {
    "version": "1.25.11"
  },
  "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).


Sorry, the tqdm example cause this issue, the `tqdm.wrapattr` did not close the file at the final.

![image](https://user-images.githubusercontent.com/4510984/124201607-18ac4b80-db0b-11eb-9586-9beeed27ebc3.png)
How to get the response from CONNECT while using proxy on a HTTPS target url

Hi,

I'm trying to send a GET to a **HTTPS** target using proxy. 
Normally(like in curl), I will receive **two** response, one is from CONNECT <https://target>, the other is from GET <https://target>
But the returning response obj from requests.get(url, proxy) only contains the second response.

Could I ask how can I get the first response from CONNECT method? And is there any method to send only CONNECT but not GET? 

Thanks a lot.

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.
Infinite loop when verify is invalid UNC path

When an invalid UNC path is passed to `requests.utils.extract_zipped_paths` it results in an infinite loop

## Expected Result

For `extract_zipped_paths` to return the path and an Exception to be thrown when the cert path is checked prior to verification being attempted.

## Actual Result

Code gets stuck looping here 
https://github.com/psf/requests/blob/5855dd711f0ab9c9c4782574b8814b1e4c7f98cc/requests/utils.py#L245-L248

## Reproduction Steps

```python
import requests.utils
requests.utils.extract_zipped_paths(r"\\localhost\a\b\c")  # Assumes this path is invalid on testing machine

```

## 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.8.10"
  },
  "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
}

```

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 code path is only hit when using a patched `certifi` package that has `certifi.where()` return a UNC path
How to upload large chunks of file in requests ?

Hello team,

I have to upload large files (~5GB). I am dividing the file in small chunks (10MB), can't send all together(as the api I am requesting fails for large data 5GB if sent in one request). The api I am uploading to,  has a specification that it needs minimum of 10MB data to be sent. I did use read(10485760) and send it via requests which works fine.

However, I do not want to read all the 10MB in the memory and if I leverage multithreading in my script, so each thread reading 10MB would cost me too much memory.

Is there a way I can send a total of 10MB to the api requests but read only 4096/8192 bytes at a time and transfer till I reach 10MB, so that I do not overuse memory.

Pls.note I don't want to send the fileobj in the requests as that will use less memory but I will not be able to break the chunk at 10MB and entire 5GB data will go to the request, which I do not want.

Is there any way via requests. I see the httplib has it. https://github.com/python/cpython/blob/3.9/Lib/http/client.py - I will call the send(fh.read(4096) function here in loop till I complete 10MB and will complete one request of 10MB without heavy memory usage.

Pls. suggest. Urgent


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.
Request fails for subdomains of localhost

Requesting subdomains of localhost fails with error message on Windows.
This error does not appear on Linux (tested on an ARM64 server).
Tested on a Windows laptop (Lenovo T14s, AMD 4750u) and a Windows desktop (AMD 2600)

## Expected Result

I need to make a get request to an url in the following format:

http://XXX.localhost (where XXX is replaced with an arbitrary value.)
example: http://ark8s-844db1a4-2988-4f30-9ff6-e78df428bad3-test.localhost

An nginx server inside kubernetes listens to this url.
When I use the url in the browser the desired site is fetched.

## Actual Result

I get the following error:
`HTTPConnectionPool(host='ark8s-844db1a4-2988-4f30-9ff6-e78df428bad3-test.localhost', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001D1E89E4940>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))`

## Reproduction Steps

```python
import requests

requests.get('http://test.localhost')
```
Same result for when 'test' is replaced with any other value no matter if a server is listening there or not.
Requesting localhost works as expected.
Subdomains of localhost do not work.

## System Information
Windows 10
Ryzen 4750U

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_pyopenssl": false
}
```

The error here `getaddrinfo failed` indicates that Python (not requests) can not find your domain name. You should be able to reproduce this with

```py
import socket

print(socket.getaddrinfo("ark8s-844db1a4-2988-4f30-9ff6-e78df428bad3-test.localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP))
```

Thank you for your answer.
Yes I get the same error there

`socket.gaierror: [Errno 11001] getaddrinfo failed`

Do you know where I can raise this issue?

It's not even just a Python issue. You could write C code and code in other languages that would encounter this. It means your machine isn't configured to resolve those addresses. Unfortunately I don't know how to do that on Windows but I suspect StackOverflow knows

Mh that is really weird.
When I enter the address on the same machine in the browser it will fetch the page.

Looked into it, the host file of Windows does not seem to support wildcards...
Damn, I guess I have to find another solution.
The subdomains are generated with entropy so i can't add them to the host file.

Thx @sigmavirus24 for pointing me in the right direction
Relax IDNA2008 requirement?

Hi all! First, thank you for all your hard work developing and maintaining requests. I know firsthand how thankless and time consuming managing an open source project can be, and I can only imagine how much more so on a project this popular. We appreciate it!

I originally raised this as https://github.com/psf/requests/issues/3687#issuecomment-835688746, after that issue was closed. I suspect no one noticed, so I'm raising as a new issue.

requests currently uses the `idna` library to check input URLs for IDNA2008 compliance, and rejects URLs that don't comply. This breaks non-compliant URLs with emoji characters, like http://☃.net/, which you all said was intentional in https://github.com/psf/requests/issues/3687#issuecomment-260757981 (also see https://github.com/psf/requests/issues/3683#issuecomment-261240279), since those domains' time is arguably limited, ie they're effectively "dead domains walking." Understood.

However, not all TLDs require IDNA2008 compliance. Unlike gTLDs, ccTLDs generally get to choose their own domain policies - [background from Wikipedia](https://en.wikipedia.org/wiki/Country_code_top-level_domain),  [ICANN](https://www.icann.org/resources/pages/cctlds-21-2012-02-25-en), [a GoDaddy representative](https://github.com/kjd/idna/issues/18#issuecomment-830969692) - and a handful of them have stuck with IDNA2003, UTS#46, or related variants.  (Not to mention older proprietary schemes like [ThaiURL](https://en.wikipedia.org/wiki/ThaiURL) 😁.) For example, [.ws, .la, .ai, .to, and .fm evidently explicitly allow emoji.](https://gizmodo.com/emoji-domains-are-the-future-maybe-1823319626)

Similarly, afaik domain owners can do whatever they want with their own subdomains. So thanks to Punycode, third level (and beyond) hostnames like https://🌏➡➡❤🔒.ayeshious.com and https://🔒🔒🔒.scotthelme.co.uk seem to not be at risk of breaking due to gTLD registries enforcing IDNA2008 on pay-level domain registrations.

Any chance you all could relax the IDNA2008 requirement so that you support both of those kinds of domains?

Right now, I'm working around this with code like this, using the `domain2idna` library, to support at least IDNA2003 in addition to IDNA2008. It'd be nice not to have to.

```py
try:
  resp = requests.get(url, ...)
except requests.exceptions.InvalidURL:
  punycode = domain2idna(url)
  if punycode != url:
    # the domain is valid idna2003 but not idna2008. encode and try again.
    resp = requests.get(punycode, ...)
```

Thanks again for listening, and for maintaining requests!

This is not likely to land as there are additional security requirements to be mindful of when using IDNA2003, hence why it's preferable to use IDNA2008. My recommendation in this case is to do the normalization yourself and pass Requests an ASCII-only host.

Fair enough, understood. Thanks for the response.
SSL ERROR - WRONG_VERSION_NUMBER

While i'm using proxies just get always this error.
I've try several times at least i resolved by removing the "s" in the https: proxy too as suggested in [this topic](https://stackoverflow.com/questions/65516325/ssl-wrong-version-number-on-python-request):

I think this problem is related to the last version, because i've tried on an older one and it works great.
## Solution Steps

```python
import requests
...
self.proxies = {
    'http': f'http://...:8080/',
    'https': f'http://...:8080/'
}
def get(self, url):
     request_url = self.base_url + url
     return requests.get(request_url, headers=self.headers, proxies=self.proxies)
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.5"
  },
  "using_pyopenssl": false
}
```


Sounds kind of like #5943 

Can you check that issue and see if it answers your question? If not, I think you need to provide some more complete example code & errors.

Almost certain this is the same issue mentioned in the comment above. Try changing https->http. Closing as duplicate.
Custom auth with Oauth2 password authentication flow does not seem to work

Summary.

I am trying to implement a OAuth2 password flow authentication process with Requests. I then rely on a Custom AUthentication method as I could not find any built-in method. Is there any?
Yet, while the prepared request seems to be fine, the final requets did not seem to pick up the header, as I get a "not authorised" error.

What you expected.

## Actual Result

What happened instead.

## Reproduction Steps

```python
import requests
import os

from requests.auth import AuthBase

username= os.environ['ADMIN_LOGIN'],
password= os.environ['ADMIN_PWD'],

class CustomAuth(AuthBase):
    """Attaches Oauth2 password Authentication to the given Request object."""
    def __init__(self, username, password):
        # setup any auth-related data here
        auth_response = requests.post(
            url = os.environ['APP_URL'] +'/api/v1/login/access-token',
            data = {
                'username': username,
                'password': password,
            }
        ).json()
        self.token = auth_response['access_token']

    def __call__(self, r):
        # modify and return the request
        r.headers['Authorization'] = 'bearer ' + self.token
        print(r.headers)
        return r

response = requests.get(
    url = os.environ['APP_URL'] +'/api/v1/orders',
    auth= CustomAuth(username, password)
)
print(response, response.content)

```

Output:
```
{'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjM3NDczNjgsInN1YiI6IjEifQ.UVDa1sfbbWByXkUWGFqSrLIN9L-0JKNepUm9BZBe5SE'}
<Response [401]> b'{"detail":"Not authenticated"}'
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.5"
  },
  "using_pyopenssl": false
}
```

Have you tried requests-oauthlib?

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.
http call throwing error in background mode

I am trying to make an HTTP call using `python-requests`. When I am running the script in the background as `python main.py &`, it works perfectly ok. But as soon as I close the terminal, it starts giving me the error "_[Errno 5] Input/output error_". The process keeps running in the background.

Any idea how to make the HTTP call while running the python script in the background (and no terminal open)?

My sample code:

```
import logging
import time

import requests

logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO,filename='log.log')
logger = logging.getLogger(__name__)

def make_req() -> None:
    res = requests.get('https://w3schools.com/python/demopage.htm')
    return res.text

def main() -> None:
    logger.info("----------------------------------------------")
    try:
        out = make_req()
        print(out)
        logger.info(out)
    except Exception as e:
        logger.error("-->"+ str(e))

if __name__ == '__main__':
    while True:
        main()
        time.sleep(5)
```

Output:
```
2021-06-10 14:03:51,840 - __main__ - INFO - ----------------------------------------------
2021-06-10 14:03:52,061 - __main__ - ERROR - -->[Errno 5] Input/output error
2021-06-10 14:03:57,081 - __main__ - INFO - ----------------------------------------------
2021-06-10 14:03:57,317 - __main__ - ERROR - -->[Errno 5] Input/output error
```

Thanks in advance.

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.
Fix GitHub links

All of these links now redirect to a repo under a different GitHub user account.

Not sure whether you want to update the changelog, but I'm happy to amend this PR if you'd rather not change `HISTORY.md`.

Thanks for the PR, @fmarier! Let’s leave the change log alone for now. I’m fine fixing the other references in the docs though.

I've removed the changelog from this PR.

Hmm, tests are failing on Python 3.6+ but it's obviously not related to this PR. Looks like something has broken in the last couple weeks. The only change I can see if urllib3 releasing a new version. We'll track that in a separate issue. Thanks again!
Minor: pip install complains (not fails) with current

Summary.
During pip install -U requests this message is sent to the terminal:

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.
requests 2.25.1 requires idna<3,>=2.5, but you have idna 3.2 which is incompatible.

## Expected Result
No such message

## Actual Result
See above

## Reproduction Steps
pip install -U idna re

## System Information

{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.5"
  },
  "platform": {
    "release": "19.6.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "101010bf"
  },
  "urllib3": {
    "version": "1.26.5"
  },
  "using_pyopenssl": false
}


We're aware, please look for existing issues before opening new ones.
JSON parameter string in requests.post


Shouldn't the content of JSON parameters be judged by type? isinstance(json_content,dict)
res = requests.post(url=url,json='{"a":1}'),In this way, the receiver needs to deserialize JSON twice to get the data

No, it's clearly documented as something that _will_ be JSON serialized with a JSON library. That means what you pass in will be passed to a serializer. Some people may want to pass a string and have that properly serialized. What would you expect to happen if we you did `json="Some text"`? That should be `"\"Some text\""` otherwise a server will never deserialize it properly.
limit the data transfer of individual HTTP requests

I have a system with limited network bandwidth.  if I make an upload or download large file operation using the requests library, the single request is consuming the whole available bandwidth of the system. is there a way to add latency to these requests (which slows down throughout of serial requests but not consume overall bandwidth)? 

A direct solution to set download/upload bandwidth for an individual HTTP request or to keep a part of the total available bandwidth free would be great.


In the future, please search **closed and** open issues before creating new ones that are duplicates.

See also #1690, #4330
page 404 through Requests but can access through browser

Trying to view a page with Requests but getting page 404 with Requests but I can access the page no problem through my browser

My Code (Sorry about how it looks, Im not familiar with using Github):
string_page = str(page)
with requests.Session() as s:

> resp = s.get('https://bscscan.com/token/generic-tokentxns2?m=normal&contractAddress=0x470862af0cf8d27ebfe0ff77b0649779c29186db&a=&sid=f58c1cdefacc680b799412c7645ed7f7&p='+string_page)

> page_info = str(resp.text)

print(page_info)

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.

Seems like a defect to me. Page works on browser, not on code. Other
similar pages work fine with my code but that one specific page does not

On Wed, May 26, 2021, 7:02 AM Ian Stapleton Cordasco <
***@***.***> wrote:

> 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.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/psf/requests/issues/5828#issuecomment-848710966>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/APBUWOVHKOQHGKTSGTQGCT3TPTPM7ANCNFSM45PPDCUQ>
> .
>
Deadlock on long requests

# Update

This seems to happen only inside WSL2, inside docker and on a Linux, it works flawlessly.

## Description

I have a HTTP service that takes around 6 minutes to make a response.

If I run cURL manually it works, I can get the result.
If I run urllib it works.
I am sure that the service returns with a HTTP 200 with JSON data. You can check running `curl -X POST "https://uc.a.run.app?user=foobar"`

But on requests it took forevers and never returns.

# Atention

This request took around 6 minutes to be completed.

I can get this work with `urllib`, but no with requests.

## Expected Result

The request be completed.

## Actual Result

The request get stuck forever on `request.post`

## Reproduction Steps

```python
import requests

url = f"https://uc.a.run.app?user=foobar"
response = requests.post(url) # THIS CALL NEVER RETURNS
print(f"{response.json()=}")
```

## System Information

    $ python -m requests.help
```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.5"
  },
  "platform": {
    "release": "5.4.72-microsoft-standard-WSL2",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "1010106f"
  },
  "urllib3": {
    "version": "1.26.4"
  },
  "using_pyopenssl": false
}
```
Timeline for fixing #5710?

I see https://github.com/psf/requests/issues/5710 says #5711 will fix an issue with using an old idna. Looks like the last movement there was Jan 20, now about 4 months ago.

Can you offer any guidance on when #5710 will be fixed?

Like others, this is blocking some of my development. In particular, I wish to try https://github.com/karolyi/py3-validate-email, which requires `idna~=3.0`, incompatible with the current requests requirements.

Hi @dfrankow,

As the last comments in both of those issues state (https://github.com/psf/requests/issues/5710#issuecomment-830211618) (https://github.com/psf/requests/pull/5711#issuecomment-764017260), this is likely to be included in the next release of Requests. The change is unfortunately breaking for a subset of users which is the reason it hasn't been merged yet.

We are pending outcomes on some other open PRs before creating the next release so there is no hard timeline. In the future, please keep discussions to the relevant issue instead of creating new ones. It creates unnecessary noise for those watching this repo and makes it difficult to track conversations on the topic. Thanks!

Thanks for your response.
The character ü gets replaced by Ã¼

I am using this library to retrieve some bibliographic information. 
If I do 
```
import requests
url = "http://dx.doi.org/10.1103/PhysRevA.96.053817" 
headers = {"accept": "application/x-bibtex"}
r = requests.get(url, headers = headers)
print(r.text)
```
I get a string that contains the character Ã¼.
Instead, that character should be ü (I also double-checked by querying directly via broswer).

Do I need to change any encoding/decoding settings?


I seem to have found a solution. Setting `r.encoding='utf-8'` does the trick,

```
import requests
url = "http://dx.doi.org/10.1103/PhysRevA.96.053817" 
headers = {"accept": "application/x-bibtex"}
r = requests.get(url, headers = headers)
r.encoding='utf-8'
print(r.text)
```
Requests ignores KeyboardInterrupt

Requests ignores CTRL+C KeyboardInterrupt when it does it's timeout.

## Expected Result
It should give up waiting when requested and exit immediately.

## Actual Result
Keeps doing it's timeout until elapse then exits.

## Reproduction Steps

```python
import requests
# an invalid url
resp = requests.get('http://192.1.5.2', timeout=50)
# press CTRL+C while executing

```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "4.0.0"
  },
  "cryptography": {
    "version": "3.1.1"
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.5"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "1010108f",
    "version": "19.1.0"
  },
  "requests": {
    "version": "2.25.1"
  },
  "system_ssl": {
    "version": "100020bf"
  },
  "urllib3": {
    "version": "1.26.3"
  },
  "using_pyopenssl": true
}
```


Hey @mrx23dot,

Thanks for the report. I took a quick look and was able to reproduce the issue. It's specific to Windows 10 and doesn't appear to happen in *nix flavor environments. A quick look at the stack trace shows the culprit isn't actually Requests, but the Python standard library. Specifically `socket.py`'s `connect` call.

You can reproduce the same issue without Requests or Urllib3 with the code below. Unfortunately, I don't think there's anything we can do here.

```python
from http.client import HTTPConnection
conn = HTTPConnection('192.1.5.2', 80, timeout=50)
conn.request('GET', '/')
conn.getresponse()
```

Thank you, created other ticket in urlib
https://github.com/urllib3/urllib3/issues/2237
Help me update csrf token for the first time sess.headers.update({'X-CSRFToken' : sess.get('https:/

Please refer to our [Stack Overflow tag](https://stackoverflow.com/questions/tagged/python-requests) for guidance.
![IMG_20210517_154240](https://user-images.githubusercontent.com/84271940/118472505-8a306600-b726-11eb-868c-da970d614d8a.jpg)
How solve this error
Please help

> Please refer to our [Stack Overflow tag](https://stackoverflow.com/questions/tagged/python-requests) for guidance.
> ![IMG_20210517_154240](https://user-images.githubusercontent.com/84271940/118472505-8a306600-b726-11eb-868c-da970d614d8a.jpg)
> How solve this error
> Please help



As you mentioned in your issue, you should direct these sorts of "how do I do X" to StackOverflow instead of using our issue tracker. The issue tracker is reserved for defects in Requests.

How can i use instacrack

On Mon, 17 May, 2021, 8:40 pm Seth Michael Larson, ***@***.***>
wrote:

> As you mentioned in your issue, you should direct these sorts of "how do I
> do X" to StackOverflow instead of using our issue tracker. The issue
> tracker is reserved for defects in Requests.
>
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly, view it on GitHub
> <https://github.com/psf/requests/issues/5819#issuecomment-842404152>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AUC6GRET2NX3YKGV4MUDAFTTOEWXFANCNFSM45AEXYDA>
> .
>
Warn user if environment variables are used

When session.verify=False, session.trust_env=True and
REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE is defined as environment
variables then, notify user that requests will use environment variables
rather than silently failing.

partially fixes: #3829

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>

I spend hours debugging this error. I am aware that this odd behavior is fixed in 3.* release.

Really nice pr, I checked it – warnings works well, can save a tons of devs time.
It would be nice to have more verbose warning text, for those who are not familiar with this problem.

> It would be nice to have more verbose warning text, for those who are not familiar with this problem.

Could you please suggest something? 😂 


Closing/re-opening since I can't trigger CI to run here

What's the status of this PR?

> I am aware that this odd behavior is fixed in 3.* release.

From #6050 looks like 3.x isn't going to happen any time soon, and commitments to fix things in 3.x don't necessarily hold.


> What's the status of this PR?

I would love to see this PR getting merged. Let me know if you need something from myside.
EOF occurred in violation of protocol

Hi Team,

I am getting this error a lot.

```
 return session.request('GET', url, **kwargs)
  File "/var/python/lib/python2.7/site-packages/requests-2.21.0-py2.7.egg/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/var/python/lib/python2.7/site-packages/requests-2.21.0-py2.7.egg/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/var/python/lib/python2.7/site-packages/requests-2.21.0-py2.7.egg/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
SSLError: HTTPSConnectionPool(host='myservce.company.com', port=443): Max retries exceeded with url: /some/url/(Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)'),))

```
currently using:  2.7.14

When I took traces, server is abruptly closing connection instead of sending server hello. 

Please help thank you in Advance.

Below we are setting poolmanager
```
def init_poolmanager(self, *pool_args, **pool_kwargs):
        ctx = ssl_.create_urllib3_context(ciphers=CIPHERS, cert_reqs=ssl.CERT_REQUIRED, options=self.ssl_options)
        #import pdb; pdb.set_trace()
        self.poolmanager = PoolManager(*pool_args,
                                       ssl_context=ctx,
                                       **pool_kwargs)
```


And the way I am getting request


```
def get_request(self, url, **kwargs):
        kwargs.setdefault('allow_redirects', True)
        adapter = HTTPService(ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1)
        session = requests.session()
        session.mount(HTTPS, adapter)
        return session.request('GET', url, **kwargs)
```


  

> When I took traces, server is abruptly closing connection instead of sending server hello.

This is the problem. There's nothing for Requests to do here as it's not a bug in requests but the nature of network programming.
Updated to new be-cordial-or-be-on-your-way URL and CoC now references Python Community CoC

The current  documentation contains two references to Kenneth Reitz's "Be Cordial or Be on Your Way" but the URL for this has now changed. The PR replaces these with the current URL.

@nateprewitt I think we should switch to a _real_ CoC, i.e., the PSF CoC. I didn't realize this was still listed as our CoC since we're in the PSF's org

Yep, totally fine by me, let's do it.

@MarkCBell would you be willing to do that? You might look at how other github.com/psf repositories are linking to the PSF Code of Conduct to see how that works for those projects

@sigmavirus24 Yes, that sounds like a sensible idea and something I can do. I'll update this PR in a couple of hours with a new candidate CoC.

@sigmavirus24 I've now updated this PR to include a CoC which references the Python Community Code of Conduct. I based this on black's CoC (it was the only repositories in github.com/psf with a CoC). Let me know if you have any suggestions for changes to this initial version.

Thanks @MarkCBell
Chardet Licence

Hey :),

I have an question regarding the licensing and a sub module you are using. As builded our application which uses flask (and flask uses requests) I noticed that a tiny package with the name chardet appeared in our installation that is licenced under GNU. As far as I understand has GNU a copyleft. 

Since your package uses the chardet lib and builds up on the top of it's coding source I am confused that the requests lib is licenced under Apache 2.0 and not GNU. As far as I understand has GNU a strict copyleft which means that even if only library calls are used the whole software that is using it should be licenced under gpl.

Maybe it is just me that misinterpret the rights and duties that come along with GNU. Just want to be sure I do not redistribute our closed source software when I have to put it under GNU.

Thanks in advance :).



 

Okay forget about it just found out that it is fine with Lesser GPL and chardet is licensed under this terms. 

Hey I have the same question. Chardet is using LGPL 2.1 licensing. Isn't it a copyleft license?