splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Browser instance on a network with proxy

Open cassionandi opened this issue 15 years ago • 40 comments

Hi.

I'm trying to run Splinter in a Windows 7 machine, in a local network that needs a proxy.

When a new instance of the Browser() is created in the python shell, a firefox window pop-ups with the profile different than the one that I use. So, this new instance and profile don't have none of the configs for proxy.

This is the message generated by the "browser = Browser()" code:

Traceback (most recent call last): File "C:\Users\cassio.nandi\Desktop\splinter\exemplo.py", line 3, in browser = Browser() File "C:\Python27\lib\site-packages\splinter\browser.py", line 46, in Browser return driver(_args, *_kwargs) File "C:\Python27\lib\site-packages\splinter\driver\webdriver\firefox.py", line 23, in init self.driver = Firefox(firefox_profile) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 47, in init desired_capabilities=DesiredCapabilities.FIREFOX) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 61, in init self.start_session(desired_capabilities, browser_profile) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in start_session 'desiredCapabilities': desired_capabilities, File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 144, in execute self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 100, in check_response raise exception_class(value) WebDriverException: Message: '\n\nERRO: A URL solicitada não pode ser recuperada\n\n\n

ERRO

\n

A URL solicitada não pode ser recuperada

\n
\n

\nNa tentativa de recuperar a URL:\nhttp://127.0.0.1:51372/hub/session\n

\nO seguinte erro foi encontrado:\n

    \n
  • \n\nProibido o Acesso.\n\n

    \nO controle de acessos impediu sua requisição.\nCaso você não concorde com isso, por favor, \ncontate seu provedor de serviços, ou o administrador de sistemas.\n

\n

\n\n\n
\n
\n
\nGenerated Tue, 08 Nov 2011 18:27:08 GMT by proxy (squid/2.6.STABLE21)\n
\n\n'

cassionandi avatar Nov 08 '11 18:11 cassionandi

Marked as a bug. Thanks for reporting.

fsouza avatar Nov 08 '11 18:11 fsouza

How do you use this proxy? Is a configuration on SO or a plugin in firefox?

tarsisazevedo avatar Nov 08 '11 19:11 tarsisazevedo

On a pt-br firefox

Opções -> Avançado -> Rede -> Configurar Conexão.

Configuração manual de proxy

Usar este proxy para todos os protocolos

cassionandi avatar Nov 08 '11 19:11 cassionandi

this configuration works on any instances of firefox?

tarsisazevedo avatar Nov 08 '11 19:11 tarsisazevedo

It is not present in the intance opened by the splinter, I supose because the temporary profile created on-the-fly.

cassionandi avatar Nov 08 '11 19:11 cassionandi

try open it with your firefox profile

tarsisazevedo avatar Nov 08 '11 19:11 tarsisazevedo

I configured the IE network settings with the proxy and to ignore 127.0.0.1. This makes everything work fine, but I need to say that my profile was loaded but ignored and overided by the system network config

cassionandi avatar Nov 09 '11 19:11 cassionandi

The problem related to httplib.

More details: http://groups.google.com/group/splinter-users/msg/1d9c0e89d1e34e23

fsouza avatar Nov 10 '11 18:11 fsouza

Howdy!

This question, like Francisco said, is related to httplib, once it doesn't look for proxy configs in your system. It could be solved with urllib2 easily, I haven't done this yet because this would cause an interface change in splinter, we would have to remove the status_code property from the webdrivers, which was implemented solving issue 35. The reason why we can't keep it, is that urllib2 does not give us access to http status code when we make a request, only when it raises an HTTPError.

The status_code support was not the goal of issue 35, it's a gain.

I'm bringing this up because the status_code is part of the webdriver's api, and remove it will break people who are using it.

flavianmissi avatar Nov 15 '11 18:11 flavianmissi

If the problem is that urllib2 doesn't provide the status_code of every page, we can move straight to urllib3, as it provides the status_code of every request.

What do you think about it?

douglascamata avatar Nov 15 '11 23:11 douglascamata

Howdy! Maybe it's a good idea, but I read (not carefully :P) the urlilb3 docs, and I didn't found any way to configure a proxy with authentication, if it not support this feature, we're gonna be in the same place we are right now, with httplib.

Do you have a link showing how to do that with urllib3? Just in case that I haven't seen this (what probably happened).

flavianmissi avatar Nov 16 '11 00:11 flavianmissi

I heard something about httplib2 giving support to proxy.

cassionandi avatar Nov 16 '11 10:11 cassionandi

Looks like httplib2 only supports SOCKS proxies without authentication. I still think we should use urllib3, so we can fetch all those status_code and will have increased performance in some cases. In my opinion, there's no networking library for python with support to authenticated proxies.

douglascamata avatar Nov 17 '11 04:11 douglascamata

Hey! I haven't seen httplib2 yet.. so I can't say anything about it right now. This is our requirements:

  • support proxy with authentication
  • have a status_code attribute

@douglascamata do you have a link that shows urllib3 proxy authentication sopport? I was not able to find it myself..

flavianmissi avatar Nov 17 '11 11:11 flavianmissi

@flaviamissi no, and I can't find any python lib that can do that.

douglascamata avatar Nov 17 '11 15:11 douglascamata

Well, don't know if you have found any resources related to 'urllib and proxy support', but this might help:

  • http://stackoverflow.com/questions/1481398/python-urllib2-https-and-proxy-ntlm-authentication
  • http://code.activestate.com/recipes/301740-simplest-useful-https-with-basic-proxy-authenticat/
  • http://www.daniweb.com/software-development/python/threads/323587

and the best one (tooked from http://bytes.com/topic/python/answers/22918-proxy-authentication-using-urllib2):

import urllib2

proxy_info = {
'user' : 'username',
'pass' : 'password',
'host' : "proxy.name.com",
'port' : 80 # or 8080 or whatever
}

# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" : \
"http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)

# install it
urllib2.install_opener(opener)

# use it
f = urllib2.urlopen('http://www.python.org/')
print f.headers
print f.read()

gabriellima avatar Nov 17 '11 19:11 gabriellima

Big thanks @gabriellima, I'll try to make it work with urllib3.

douglascamata avatar Nov 17 '11 19:11 douglascamata

@gabriellima Yes, as I said before, I know urllib2 has this support, they have an example just like yours in the docs, what urllib2 doesn't have is a status_code, that we also need.

But thank's for the sample.

flavianmissi avatar Nov 17 '11 20:11 flavianmissi

Now I got what you mean. Hope you find this 'status_code' attribute helper :)

Good luck :)

Ahh, doesn't it come with the response of trying to access the page? I don't know urllib fairly well.

gabriellima avatar Nov 17 '11 22:11 gabriellima

I'm removing the "bug" label. We were not expecting to support this feature :)

fsouza avatar Nov 24 '11 12:11 fsouza