0

I need to get some data from the internet but I'm behind corporate proxy and I do not know a password. So I tried many examples with pyRequests module but always I get only message 'Authorization failed ...'.

So I am just thinking if this idea is possible: Main setup for proxy is stored in the IE (connection tab in settings) and I am also using Chrome and if I understand well Chrome is using this setup for access to internet (because when I open proxy setting in Chrome, the IE Proxy Setting Window popup).

So my question is if I can also use (somehow) this setting for my python script and how (without knowing password).

Lodhart
  • 205
  • 1
  • 6
  • 14
  • If you could use proxies in Chrome, you should have access to these proxies through `requests`. – flyer Dec 12 '13 at 07:57
  • Maybe I do not know how it exactly works. I do not have password for proxy. I tried to use user name and password which I get for Windows but it is not working for me. – Lodhart Dec 12 '13 at 10:04

2 Answers2

2

By using the Python urllib module you can programmatically obtain the proxies on your system in a platform independent way using the urllib.request.getproxies function:

import urllib
urllib.request.getproxies()

This function will first check for any proxies set in the environment variables (e.g. http_proxy etc) or if none are set then it will check for system configured proxies using platform specific calls (e.g. On MacOS it will check using the system scutil/configd interfaces, and on Windows it will check the Registry).

Pierz
  • 7,064
  • 52
  • 59
  • It's empty ... see the output below `>>> import urllib >>> urllib.request.getproxies() {} >>>` –  Dec 23 '18 at 12:23
  • That means there’s no system proxy configured. – Pierz Dec 23 '18 at 15:19
  • 3
    For new versions of python use: import urllib.request. According to https://stackoverflow.com/a/41217363/7281675. – keramat Aug 26 '20 at 10:54
0

There are known (UNIX) operating system environment variables whi Python support for proxying. Also, for Windows, it should try to read settings from OS registry in the case it is possible: https://mail.python.org/pipermail/tutor/2008-December/065573.html

Proxy settings are used e.g. by

  • pip

  • urllib

  • requests

... as far as I know.

If Python fails to get proxy settings from Windows it would be worth of investigating by running test scripts which use urllib proxy functions (see link above).

Examples how to set HTTP(S) proxy for Python:

How to tell Python to automatically use the proxy setting in Windows XP like R's internet2 option?

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • When I add a variable for HTTP_PROXY, instead of connection failed I get just 'Access is denieddue to .... Authentication Failed' It is tha same when I use connect to proxy with requests module. – Lodhart Dec 12 '13 at 09:43
  • Does your proxy require username and password? – Mikko Ohtamaa Dec 12 '13 at 10:32
  • Yes it does, but it does not work with my Windows account. I hope that if IE and Chrome is working, I can 're-use' access to the internet. – Lodhart Dec 12 '13 at 12:36