Search code examples
python-requests-html

"requests-html" proxy setting not working


I'm using the following code to set the proxy for the HTMLSession, get() method. Still, it uses my IP instead of the proxy IP.

proxy string format:

http://username:password@ip:port

r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy})
r.html.find('p.ip-address')[0].text

above print the following which is my current IP address.

'IPv4:? The most common IP version is assigned by ISPs. 175.157.?.?'

Solution

  • You need to add 'https' in proxies:

    proxy = 'http://username:password@ip:port'
    r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy, 'https': proxy})