[python-win32] Re: win32com: HTTP Post with WebBrowser.Navigate()

Roger Upole rwupole at msn.com
Sat Aug 27 05:46:22 CEST 2005


Try PostData=buffer(Data).

    hth
         Roger


Troy Farrell wrote:
> I've made some progress.  I finally coerced IE to POST, but the data it
> posts is ugly binary data, not what I thought I sent in PostData:
>
> ---Begin Python Code---
> import win32com.client
>
> # Prepare Internet Explorer
> ie = win32com.client.Dispatch( "InternetExplorer.Application.1" )
>
> dURL = "http://server/cgi-bin/test.sh"
> Flags = 0
> Huh = ""
> Data = "TEST=SUCCESS"
> PostData = [ Data ]
> Headers = "Content-Type: application/x-www-form-urlencoded\r\n"
>
> # show it to the user
> ie.Visible = True
> ie.Navigate( dURL, Flags, Huh, PostData, Headers )
>
> ---End Python Code---
>
> Where a the QUERY_STRING would be posted, "TEST=SUCCESS" in the example
> above, I'm getting wierd binary data:
>
> POST /cgi-bin/test/sh HTTP/1.1
> Accept: */*
> Accept-Language: en-us,ru;q=0.8,fr;q=0.5,et;q=0.3
> Content-Type: application/x-www-form-urlencoded
> Accept-Encoding: gzip, deflate
> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
> 1.1.4322; .NET CLR 2.0.50215)
> Host: server
> Content-Length: 16
> Connection: Keep-Alive
> Cache-Control: no-cache
>
> .........}......
>
> The POSTed data formatted in a python array:
> [ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x7d, 0x19, 0x00,
> 0x00, 0x00, 0x00, 0x00 ]
>
> I suspect this is due to a disagreement between Python and COM over the
> PostData argument.  In more than one place on support.microsoft.com and
> MSDN I have seen this:
> """
> The post data specified by PostData is passed as a SAFEARRAY Data Type
> structure. The VARIANT should be of type VT_ARRAY and point to a SAFEARRAY
> Data Type. The SAFEARRAY Data Type should be of element type VT_UI1,
> dimension one, and have an element count equal to the number of bytes of
> post data.
> """
>
> This was mentioned long ago on the python list:
> http://mail.python.org/pipermail/python-list/2002-July/113260.html
>
> Does anyone know how I might go about fixing this argument?  This is where
> I mention that I have little/no COM experience outside of python.
>
> Thanks.
> Troy
>



More information about the Python-win32 mailing list