Mechanicalsoup Proxy in python

Asked

Viewed 88 times

0

Regarding Python requests using mechanicalsoup, how do I open the site using a proxy.

import mechanicalsoup

br = mechanicalsoup.StatefulBrowser()

site = 'www.exemplo.com.br'

open = br.open(site)

resp = open.text

print(resp)

1 answer

0

Through session.proxies:

import mechanicalsoup

br = mechanicalsoup.StatefulBrowser()
site = 'www.exemplo.com.br'

proxies = {
    'https': 'my.https.proxy:8080',
    'http':  'my.http.proxy:8080'
}
br.session.proxies = proxies

open = br.open(site)
resp = open.text
print(resp)
  • (Caused by Proxyerror('Cannot connect to proxy. ', Newconnectionerror('<urllib3.connection.Verifiedhttpsconnection Object at 0x0316AC70>: Failed to Establish a new Connection: [Errno 11004] getaddrinfo failed'

  • @Jhoonyfr0id "cannot connect to proxy" -> seems to be something wrong with your proxy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.