'How to use requests with IPV6 without hard code interface name in urllib3/util/connection.py - create_connection?
My OS is CentOS 72, with requests 2.27.1, Python3.9.0, I want to visit my page by Ipv6, but it return 400 - Bad Request
Code is
>>> import requests
>>> requests.packages.urllib3.disable_warnings()
>>> url = 'https://[fe80::2ac1:3cff:fe89:a728%enp0s3]/#login'
>>> res = requests.get(url, verify=False)
>>> res.status_code
400
Then I change url to https://[fe80::2ac1:3cff:fe89:a728]/#login, urllib3 will raise OSError: [Errno 22] Invalid argument
So I hard code interface name in urllib3/util/connection.py - create_connection like this
family = allowed_gai_family()
print('Before Change: {0}'.format(host))
host = '{0}%enp0s3'.format(host)
print('After Change: {0}'.format(host))
It can visit successfully
>>> import requests
>>> requests.packages.urllib3.disable_warnings()
>>> url = 'https://[fe80::2ac1:3cff:fe89:a728]/#login'
>>> res = requests.get(url, verify=False)
Before Change: fe80::2ac1:3cff:fe89:a728
After Change: fe80::2ac1:3cff:fe89:a728%enp0s3
>>> res.status_code
200
Does it can work without hard code interface name in create_connect ??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
