Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 270881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:04:21+00:00 2026-05-12T00:04:21+00:00

I’m trying to use a feature of the Microsoft WinHttp library that has been

  • 0

I’m trying to use a feature of the Microsoft WinHttp library that has been exposed by the developers of Win32com. Unfortunately most of the library does not seem to be documented and there are no example of the correct way to use the win32inet features via the win32com library.

This is what I have so far:

import win32inet
hinternet = win32inet.InternetOpen("foo 1.0", 0, "", "", 0)
# Does not work!!!
proxy = win32inet.WinHttpGetProxyForUrl( hinternet, u"http://www.foo.com", 0  )

As you can see, all I am trying to do is use the win32inet feature to find out which proxy is the appropriate one to use for a given URL, int his case foo.com.

Can you help me correct the syntax of the last line? MSN has some good documentation for the function being wrapped but the args do not seem to map the to those of the python library perfectly.

The fixed version of this script should:

  • Be able to look up which proxy to use
    for any given URL.

  • It should always do exactly what Internet Explorer would do (i.e. use the same proxy)

  • It should be valid on any valid Windows XP set-up. That means it should work with an explicitly configured proxy and also no proxy at all.

  • It only needs to work on Windows XP 32bit with Python 2.4.4. It can use any official released version of win32com.

I’m using Python2.4.4 with Win32Com on Windows XP.

UPDATE 0:

OR… can you give me an alternative implementation in cTypes? As long as I can make it work I’m happy!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:04:21+00:00Added an answer on May 12, 2026 at 12:04 am

    Here is the code which creates HINTERNET session and uses that to get proxy details, using ctypes to directly access winhttp DLL.
    It works without any error but I have no proxy set on my machine, you may have to tweak few constants to get it right. Go thru the msdn links in code, from where I have seen the API.

    import ctypes
    import ctypes.wintypes
    
    winHttp = ctypes.windll.LoadLibrary("Winhttp.dll")
    
    # http://msdn.microsoft.com/en-us/library/aa384098(VS.85).aspx
    # first get a handle to HTTP session
    WINHTTP_ACCESS_TYPE_DEFAULT_PROXY=0
    WINHTTP_NO_PROXY_NAME=WINHTTP_NO_PROXY_BYPASS=0
    WINHTTP_FLAG_ASYNC=0x10000000
    HINTERNET = winHttp.WinHttpOpen("PyWin32", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC)
    print HINTERNET
    
    # now get proxy using HTTP session
    # http://msdn.microsoft.com/en-us/library/aa384097(VS.85).aspx
    """
    BOOL WinHttpGetProxyForUrl(
      __in   HINTERNET hSession,
      __in   LPCWSTR lpcwszUrl,
      __in   WINHTTP_AUTOPROXY_OPTIONS *pAutoProxyOptions,
      __out  WINHTTP_PROXY_INFO *pProxyInfo
    );
    """
    # create C structure for WINHTTP_AUTOPROXY_OPTIONS
    #http://msdn.microsoft.com/en-us/library/aa384123(VS.85).aspx
    """
    typedef struct {
      DWORD   dwFlags;
      DWORD   dwAutoDetectFlags;
      LPCWSTR lpszAutoConfigUrl;
      LPVOID  lpvReserved;
      DWORD   dwReserved;
      BOOL    fAutoLogonIfChallenged;
    } WINHTTP_AUTOPROXY_OPTIONS;
    """
    class WINHTTP_AUTOPROXY_OPTIONS(ctypes.Structure):
        _fields_ = [("dwFlags", ctypes.wintypes.DWORD),
                    ("dwAutoDetectFlags", ctypes.wintypes.DWORD),
                    ("lpszAutoConfigUrl", ctypes.wintypes.LPCWSTR),
                    ("lpvReserved", ctypes.c_void_p ),
                    ("dwReserved", ctypes.wintypes.DWORD),
                    ("fAutoLogonIfChallenged",ctypes.wintypes.BOOL),]
    
    WINHTTP_AUTOPROXY_AUTO_DETECT = 0x00000001;
    WINHTTP_AUTO_DETECT_TYPE_DHCP = 0x00000001;
    WINHTTP_AUTO_DETECT_TYPE_DNS_A = 0x00000002;
    options = WINHTTP_AUTOPROXY_OPTIONS()
    options.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT
    options.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP|WINHTTP_AUTO_DETECT_TYPE_DNS_A
    options.lpszAutoConfigUrl = 0
    options.fAutoLogonIfChallenged = False
    
    # create C structure for WINHTTP_AUTOPROXY_OPTIONS
    # http://msdn.microsoft.com/en-us/library/aa383912(VS.85).aspx
    """
    struct WINHTTP_PROXY_INFO {
      DWORD  dwAccessType;
      LPWSTR lpszProxy;
      LPWSTR lpszProxyBypass;
    };
    """
    class WINHTTP_PROXY_INFO(ctypes.Structure):
        _fields_ = [("dwAccessType", ctypes.wintypes.DWORD),
                    ("lpszProxy", ctypes.wintypes.LPCWSTR),
                    ("lpszProxyBypass", ctypes.wintypes.LPCWSTR),]
    
    info = WINHTTP_PROXY_INFO()
    
    ret = winHttp.WinHttpGetProxyForUrl(HINTERNET, "http://www.google.com", ctypes.pointer(options), ctypes.pointer(info) )
    print "proxy success?",ret
    if not ret:
        # some error lets see what is that?
        import win32api
        import win32con
        errorCode = win32api.GetLastError()
        print "win32 Error:",errorCode
        s = ""
        print win32api.FormatMessage(errorCode)
    
    print info.dwAccessType, info.lpszProxy, info.lpszProxyBypass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.