Requests giving errors while using HTTP proxies - python

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).

Related

Proxy authentication with python requests

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!

How to solve HTTPSConnectionPool(host='graph.facebook.com', port=443): Max retries exceeded with url

I am trying to post something on Facebook
def make_post():
caption = post_caption()
url = (
f"https://graph.facebook.com/{config.page_id}/photos?"
f"caption={caption}&access_token={config.token}"
)
files = {
'image': open(pimage, "rb")
}
if config.dry_run:
return dummy_response
response = requests.post(url, files=files)
return response.json()
but it gave me this error
HTTPSConnectionPool(host='graph.facebook.com', port=443): Max retries exceeded with url: (Caused by NewConnectionError('urllib3.connection.HTTPSConnection object at 0x000001AD174AA5B0>: 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'))
I have searched here in stackoverflow but I didn't find anything that works sorry I am new to this site, if I did anything wrong.

Cannot connect to proxy error requests.get (python)

I am trying to connect to a proxy with requests.get, and whenever I try, I get a cannot connect to proxy error. Here is my code:
import requests
proxies = {
"http": "181.113.68.196:8080",
"https": "181.113.68.196:8080",
}
r = requests.get("https://thewebsite.com", proxies=proxies)
That ouputs this error:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='thewebsite.com', port=443): Max retries exceeded with url: /python-requests-proxy (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))
Im just putting thewebsite.com because it does the same thing with all of the websites I input. Can anyone help me with this?

How to catch exception MaxRetryError?

I have a list of proxy addresses for which I want to connect the telegrams-bot.
Proxies can be blocked over time or simply not work, this can be seen by the MaxRetryError error.
But I can't catch an error. I have an error in logs.
I want to catch an error and switch to another proxy server.
from telegram.ext import Updater
REQUEST_KWARGS = {
'proxy_url': proxy_url,
'urllib3_proxy_kwargs': {
'retries': 0
}
}
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
.....
raise MaxRetryError(_pool, url, error or ResponseError(cause))
telegram.vendor.ptb_urllib3.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
......
telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
2019-07-26 16:07:38,553 - telegram.ext.dispatcher - CRITICAL - stopping due to exception in another thread
This way ?
try:
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
except MaxRetryError:
#doSomething

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?

Categories