1

I'am trying to edit/configure a proxy server using python on windows using below code. But i get an error. Need help !!

import winreg

INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
    r'Software\Microsoft\Windows\CurrentVersion\Internet Settings',
    0, winreg.KEY_ALL_ACCESS)

def set_key(name, value):
    _, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, name)
    winreg.SetValueEx(INTERNET_SETTINGS, name, 0, reg_type, value)

set_key('ProxyEnable', 1)
set_key('ProxyServer', u'192.168.0.5:3128')
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Am using Windows 8 I get the below Error >>> set_key('ProxyServer', u'192.168.0.5:3128') Traceback (most recent call last): File "", line 1, in File "", line 2, in set_key FileNotFoundError: [WinError 2] The system cannot find the file specified – user3455595 Jun 18 '14 at 07:25
  • (Don't have enough reputation to flag as duplicate) [Change browser proxy settings from Python?](http://stackoverflow.com/questions/3050262/change-browser-proxy-settings-from-python) – Richard Muthwill Jun 18 '14 at 07:28
  • I was referring to the same above link for my use case. But, the last line in the code gave error as i reported. want to get rid of this Thanks – user3455595 Jun 18 '14 at 07:32
  • Can i get some help in getting this work ? – user3455595 Jun 18 '14 at 11:11

1 Answers1

0

You are getting the error because you are trying to query for a key that does not exist yet. You need to create the key in your registry. Setting the value direclty also creates the key.

INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Internet Settings',
0, winreg.KEY_ALL_ACCESS)

winreg.SetValueEx(INTERNET_SETTINGS, "ProxyServer", 0, winreg.REG_SZ, "your server address")
ched
  • 83
  • 3
  • 10