Home Download Buy Blog Forum Support

Configuring ST2 Proxy settings

Configuring ST2 Proxy settings

Postby cyanide911 on Fri Feb 22, 2013 12:26 pm

I've a simple script which uses urllib2.urlopen(). If I run it via the terminal with 'python script.py', it runs flawlessly.
But if I run it in sublime text 2 via 'CTRL+B', it gives me this error

Code: Select all
"Traceback (most recent call last):
  File "/path/to/script/script.py", line 10, in <module>
    response = urllib2.urlopen("http://google.com")
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 406, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 444, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required
[Finished in 0.4s with exit code 1]"

My proxy is set in the http_proxy and https_proxy environment variables and in /etc/environment.

What do I need to configure for using urllib2 in ST2. And no I don't want to use Requests :P
Posts: 2
Joined: Fri Feb 22, 2013 12:21 pm

Re: Configuring ST2 Proxy settings

Postby schlamar on Fri Feb 22, 2013 2:16 pm

Sublime doesn't pick all environment variables (especially those defined in .bashrc/.profile/...). So a solution would be to define the proxy manually in your script:

Code: Select all
import os
os.environ['http_proxy'] = 'http://.../'

cyanide911 wrote:And no I don't want to use Requests :P

Proxy support is broken in requests, anyway :)
Posts: 108
Joined: Tue Feb 19, 2013 2:11 pm

Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests