Hi i am trying to do an action with a session like this:
with requests.Session() as ses:
s = ses.get(f"URL")
my proxy format is: http://username:password@url_of_proxyprovider:port
i tried using in this case: ses.proxies.update(proxy) but it didnt work.
also tried this, but didnt work: s.proxies = {'proxy'}
also tried adding proxy like this: s = ses.get(f"url", proxies=proxy)
its always done through my IP and not through the proxy.
>Solution :
Converting comment to answer.
The correct way to do it:
import requests
with requests.Session() as session
session.proxies = {
'http': 'http://username:password@url_of_proxyprovider:port',
'https': 'http://username:password@url_of_proxyprovider:port'
}
url = 'http://mywebsite.com/example'
response = session.get(url)
If you want to proxy FTP also, you can add it to the proxies dictionary:
session.proxies = {
'http': 'http://username:password@url_of_proxyprovider:port',
'https': 'http://username:password@url_of_proxyprovider:port',
'ftp': 'http://username:password@url_of_proxyprovider:port'
}