Monthly Archives: January 2014

Install Package Control from behind a proxy (SublimeText3)

The default install script is given by “Package Control” website :

The simplest method of installation is through the Sublime Text console. The console is accessed via the ctrl+` shortcut or the View > Show Console menu. Once open, paste the code into the console.

import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

However if you’re behind a proxy you’ll have to add the proxy infos in the urllib.request.ProxyHandler() object creation like this :

urllib.request.ProxyHandler(
  {"http":"http://[proxy_user]:[proxy_password]@[proxy_IP]:[proxy_port]"}
)

Here is the online code you should modify (Replace [proxy_*] by their value):

import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler({"http":"http://[proxy_username]:[proxy_password]@[proxy_IP_or_host]:[proxy_port]"})) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by);

___
You haven’t finished yet since you now should configure the proxy in Package Control configuration so it’ll be able to access internet :
Go to Preferences > Package Settings > Package Control > Settings – User
On first install it should be empty, just add these lines (Replace [proxy_*] by their value):

{
    "proxy_username":"[proxy_password]",
    "proxy_password":"[proxy_username]",
    "http_proxy":"[proxy_IP_or_host]:[proxy_port]",
    "https_proxy":"[proxy_IP_or_host]:[proxy_port]",
}