Re: Classic ASP -> Response.Cookies access

Mark Hammond <[email protected]> Wed, 23 Oct 2024 22:53:00 -0400
Newsgroups gmane.comp.python.windows
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============8441420255549798499==
Content-Type: multipart/alternative;
 boundary="------------BtilYF0NNpff0B2tC1Swan08"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------BtilYF0NNpff0B2tC1Swan08
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

On 2024-10-23 7:42 p.m., Steven Manross wrote:

> I’m not sure if this is implemented or not in the Python ASP code or 
> not, but I am trying to duplicate some VBS code in Python, and use the 
> URL below as a primer as I couldn’t find any info on the internet 
> about how Python might implement this kind of ASP code.
>
> I know the link is SUPER OLD but it’s the best docs I have been able 
> to find on the subject.
>
> https://learn.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524757(v=vs.90)
>
> I am trying to create cookies similar to how the Microsoft Certificate 
> Authority Website on Windows Server 2016/2019/2022 does.
>
> Here’s my Python ASP code
>
> <% @Language="Python"%>
>
> <%
>
> Response.Write("Here<BR>")
>
> for cookie in Response.Cookies:
>
> Response.Write(Response.Cookies(cookie)["expires"])
>
> Response.Write(f"dir = {Response.Cookies.__dir__()}")
>
> if not "Type" in Response.Cookies:
>
>     cookie = Response.Cookies["type"] = "peanut-butter" # simplistic 
> example of trying to create one
>
> Response.Write("Past Cookie Creation code<BR>")
>
> %>
>
> Here’s my error:
>
> Python ActiveX Scripting Engine error '80020009'
>
> Traceback (most recent call last): File "<Script Block >", line 3, in 
> <module> cookie = Response.Cookies["type"] = "peanut-butter" File 
> "C:\Python310\lib\site-packages\win32com\client\dynamic.py", line 348, 
> in __setitem__ self._oleobj_.Invoke(*allArgs), 
> self._olerepr_.defaultDispatchName, None COM Error: OLE error 0x80020101
>
> /testcookies.asp, line 5
>
> cookie = Response.Cookies["type"] = "peanut-butter"
>
> Any guidance would be appreciated as I’ve scoured google for all it 
> was worth.
>
Response.Cookies is "just" a dynamic COM object/collection and pywin32 
has never been great with them and "magic" things like properties etc 
due to various semantic mismatches. If you are lucky, there might be a 
method on the object taking 2 params? I'm guessing `__dir__` didn't help?

Regardless, a last resort would be to unwrap that __setitem__ call and 
experiment with the correct "DISPATCH_*" flags (and in particular, 
trying "DISPATCH_METHOD", because the examples are all showing function 
calls to "set" a value, which python has no concept of!) - the other 
values are probably correct.

HTH,

Mark


--------------BtilYF0NNpff0B2tC1Swan08
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>On 2024-10-23 7:42 p.m., Steven Manross wrote:</p>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator"
        content="Microsoft Word 15 (filtered medium)">
      <style>@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;
	mso-ligatures:standardcontextual;}a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri",sans-serif;
	color:windowtext;}.MsoChpDefault
	{mso-style-type:export-only;}div.WordSection1
	{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">I’m not sure if this is implemented or not
          in the Python ASP code or not, but I am trying to duplicate
          some VBS code in Python, and use the URL below as a primer as
          I couldn’t find any info on the internet about how Python
          might implement this kind of ASP code.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I know the link is SUPER OLD but it’s the
          best docs I have been able to find on the subject.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><a
href="https://learn.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524757(v=vs.90)"
            moz-do-not-send="true" class="moz-txt-link-freetext">https://learn.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524757(v=vs.90)</a><o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I am trying to create cookies similar to
          how the Microsoft Certificate Authority Website on Windows
          Server 2016/2019/2022 does.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Here’s my Python ASP code<o:p></o:p></p>
        <p class="MsoNormal">&lt;% @Language="Python"%&gt;<o:p></o:p></p>
        <p class="MsoNormal">&lt;%<o:p></o:p></p>
        <p class="MsoNormal">Response.Write("Here&lt;BR&gt;")<o:p></o:p></p>
        <p class="MsoNormal">for cookie in Response.Cookies:<o:p></o:p></p>
        <p class="MsoNormal">   
          Response.Write(Response.Cookies(cookie)["expires"]) <o:p>
          </o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Response.Write(f"dir =
          {Response.Cookies.__dir__()}")<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">if not "Type" in Response.Cookies:<o:p></o:p></p>
        <p class="MsoNormal">    cookie = Response.Cookies["type"] =
          "peanut-butter" # simplistic example of trying to create one<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Response.Write("Past Cookie Creation
          code&lt;BR&gt;")<o:p></o:p></p>
        <p class="MsoNormal">%&gt;<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Here’s my error:<br>
          <br>
          <o:p></o:p></p>
        <p class="MsoNormal">Python ActiveX Scripting Engine error
          '80020009'<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Traceback (most recent call last): File
          "&lt;Script Block &gt;", line 3, in &lt;module&gt; cookie =
          Response.Cookies["type"] = "peanut-butter" File
          "C:\Python310\lib\site-packages\win32com\client\dynamic.py",
          line 348, in __setitem__ self._oleobj_.Invoke(*allArgs),
          self._olerepr_.defaultDispatchName, None COM Error: OLE error
          0x80020101<o:p></o:p></p>
        <p class="MsoNormal">/testcookies.asp, line 5<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">cookie = Response.Cookies["type"] =
          "peanut-butter"<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Any guidance would be appreciated as I’ve
          scoured google for all it was worth.</p>
      </div>
    </blockquote>
    <p>Response.Cookies is "just" a dynamic COM object/collection and
      pywin32 has never been great with them and "magic" things like
      properties etc due to various semantic mismatches. If you are
      lucky, there might be a method on the object taking 2 params? I'm
      guessing `__dir__` didn't help?</p>
    <p>Regardless, a last resort would be to unwrap that __setitem__
      call and experiment with the correct "DISPATCH_*" flags (and in
      particular, trying "DISPATCH_METHOD", because the examples are all
      showing function calls to "set" a value, which python has no
      concept of!) - the other values are probably correct.</p>
    <p>HTH,</p>
    <p>Mark<br>
    </p>
    <br>
  </body>
</html>

--------------BtilYF0NNpff0B2tC1Swan08--

--===============8441420255549798499==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32

--===============8441420255549798499==--