Proxy authentication with python requests - python

I am using the following code. I have removed the actual 'username' and 'password' and 'proxy_address' objects for privacy reasons.
auth = HTTPProxyAuth('username', 'password')
r = requests.get(hyperlink, proxies={'http': proxy_address, 'https': proxy_address},
auth=auth, timeout=5)
I get the following error:
HTTPSConnectionPool(host='bafybeihpjhkeuiq3k6nqa3fkgeigeri7iebtrsuyuey5y6vy36n345xmbi.ipfs.dweb.link', port=443): Max retries exceeded with url: /45 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
What should I do to resolve this issue? I have tried looking into the documentation for python Requests but I haven't been able to find a solution for my implementation. Thanks!

Related

How to disable SSL verification for OAuth client of Authlib Python library?

I'm using Python 3.9.12 on Windows 10. My goal is to connect to KeyCloak server through browser to fetch access token. I'm using Authlib 0.15.5 to connect to the server to fetch the authentication URL. Below is the code.
from authlib.integrations.flask_client import OAuth
oauth_client = OAuth()
oauth_client.register(
name=_configuration.oauht2_provider,
client_id=_configuration.oauth2_client_id,
client_secret=_configuration.oauth2_client_secret,
authorize_url=_configuration.oauht2_authorize_url,
authorize_params=_configuration.oauht2_authorize_params,
refresh_token_url=_configuration.oauht2_refresh_token_url,
refresh_token_params=_configuration.oauht2_refresh_token_param,
access_token_url=_configuration.oauht2_access_token_url,
access_token_params=_configuration.oauht2_access_token_params,
client_kwargs={"scope": _configuration.oauht2_scope},
server_metadata_url=_configuration.oauht2_open_id_url)
oauth_client.init_app(app=_app)
_oauth_client = oauth_client.create_client(_configuration.oauht2_provider)
redirect_url = _oauth_client.create_authorization_url(_configuration.oauth2_client_redirect_url, verify=False)['url']
The create_authorization_url is throwing this error
HTTPSConnectionPool(host='keycloak-xxxx-xxxxxxx-xxx.xx.xxxx-xxxxx-xxx.xx.xx.xx.x', port=443): Max retries exceeded with url: /auth/realms/WXYZ/.well-known/uma2-configuration (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
How can I disable SSL certification verification in the above code? Thank you.
I tried adding verify=False argument to the create_authorization_url, however, it did not work.
redirect_url = _oauth_client.create_authorization_url(_configuration.oauth2_client_redirect_url, verify=False)['url']

Requests giving errors while using HTTP proxies

So, I was sending a request using the requests library in Python 3.9.1. The problem is, when I tried to use an HTTP proxy it gave me this error:
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002B08D6BC9A0>: Failed to establish a new connection:
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))
This my code, I would appreciate any help.:
import requests
for proxy in open('proxies.txt','r').readlines():
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}'
}
e = requests.get('https://google.com/robots.txt',proxies=proxies)
open('uwu.txt','a').write(e.text)
print(e.text)
I am pretty sure it is not problem with my proxies as they are really good private proxies with 100 gigs of bandwidth. (from zenum.io).

HTTPSConnectionPool(host='xx.xx.xx.xx', port=443): Max retries exceeded with url

I would like to surpass SSL verification when I send post request with the python requests module, but it gave me an error even when I added parameter verify=False:
My request:
response = session.request(rest_body["method"], url, data=data,
headers=headers, proxies=PROXIES,
cookies=req_cookies, verify=False)
Error (new lines added):
HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /oauth/token
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object
at 0x7f174234e5f8>: Failed to establish a new connection: [Errno 111]
Connection refused',))
What does this error mean, and how can I avoid it?

Failed to establish a new connection error using Python requests Errno -2 Name or service unknown

I am trying to make a request to an API with Python. I am able to make the request with curl without issue but I have something wrong with my Python request.
Why does this code,
import requests
from requests.auth import HTTPBasicAuth
emailadd = 'user123#example.com'
domain = 'example.com'
spantoken = 'omitted'
def checkUserLicensed(useremail):
url = ('https://api.spannigbackup.com/v1/users/' + useremail)
print(url)
response = requests.get(url, auth=(domain,spantoken))
print(response)
checkUserLicensed(emailadd)
Return this error
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.spannigbackup.com', port=443): Max retries exceeded with url: /v1/users/user123#example.com
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f73ca323748>: Failed to establish a new connection: [Errno -2] Name or service not known'))

unable to connect HTTPS url in python

#!/usr/bin/python
import requests
from requests.auth import HTTPBasicAuth
requests.get('url', auth=HTTPBasicAuth('XXXX','XXXX'))
I am getting Below error
(Caused by ProxyError('Cannot connect to proxy.', error(111, 'Connection refused')
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='XXXX', port=443): Max retries exceeded with url
According to the error you use a HTTPBasicAuth instead Proxy(maybe that corporate proxy?).
Try to setup proxy credentials before the request.
$ export http_proxy='http://myproxy.example.com:1234'
$ python request.py # Using http://myproxy.example.com:1234 as a proxy
Please let me know if you use a corporate proxy.

Categories