Microsoft provides a method as part of WinHTTP which allows a user to determine which Proxy ought to be used for any given URL. It’s called WinHttpGetProxyForUrl.
Unfortunately I’m programming in python so I cannot directly access this function – I can use Win32COM to call any Microsoft service with a COM interface.
So is there any way to get access to this function from Python? As an additional problem I’m not able to add anything other than Python to the project. That means however convenient it is impossible to add C# or C++ fixes.
I’m running Python2.4.4 with Win32 extensions on Windows XP.
Update 0:
This is what I have so far:
import win32inet
import pprint
hinternet = win32inet.InternetOpen("foo 1.0", 0, "", "", 0)
# Does not work!!!
proxy = win32inet.WinHttpGetProxyForUrl( hinternet, u"http://www.foo.com", 0 )
Obviously the last line is wrong, however I cannot see any docs or examples on the right way to do it!
Update 1:
I’m going to re-ask this as a new question since it’s now really about win32com.
You can use ctypes to call function in WinHttp.dll, it is the DLL which contains ‘WinHttpGetProxyForUrl. ‘
Though to call it you will need a HINTERNET session variable, so here I am showing you the first step, it shows how you can use ctypes to call into DLL,it produces a HINTERNET which you have to pass to WinHttpGetProxyForUrl, that I will leave for you as exercise, if you feel difficulty POST the code I will try to fix it.
Read more about ctypes @ http://docs.python.org/library/ctypes.html