jborean93 / pypsrp

PowerShell Remoting Protocol for Python
MIT License
328 stars 49 forks source link

KeyError in serializer.py #155

Open BiggestSmile opened 2 years ago

BiggestSmile commented 2 years ago

Hi Jordan!

I'm getting the similar error as in issue https://github.com/jborean93/pypsrp/issues/3 and https://github.com/jborean93/pypsrp/issues/71.

My code:

import os
from pypsrp.powershell import PowerShell, RunspacePool
from pypsrp.wsman import WSMan

wsman = WSMan(os.environ.get("SPCA_IP", ""),
              username=os.environ.get("DOMAIN", "") + "\\" + os.environ.get("AD_USER", ""),
              password=os.environ.get("AD_PASS", ""),
              ssl=False)

with RunspacePool(wsman) as pool:
    ps = PowerShell(pool)
    script = '''begin {
                        Add-PSSnapin Microsoft.SharePoint.PowerShell
                        Get-SPSite -Identity http://ws2019std-shp/sites/team_site_1 | Get-SPWeb -Limit ALL
                }'''
    ps.add_script(script)
    output = ps.invoke()

Error Traceback:

Traceback (most recent call last):
  File "/content/portal/portal_backend/con_ms_shp_farm/services/examples_pack/04_PSRP.py", line 37, in <module>
    output = ps.invoke()
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 1218, in invoke
    return self.end_invoke()
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 1190, in end_invoke
    self.poll_invoke()
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 1391, in poll_invoke
    responses = self.runspace_pool._receive(self.id, timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 683, in _receive
    return self._parse_responses(response, pipeline)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 690, in _parse_responses
    messages = self._fragmenter.defragment(responses)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 1634, in defragment
    messages = [Message.unpack(fragment, self.serializer) for fragment in fragments]
  File "/usr/local/lib/python3.9/site-packages/pypsrp/powershell.py", line 1634, in <listcomp>
    messages = [Message.unpack(fragment, self.serializer) for fragment in fragments]
  File "/usr/local/lib/python3.9/site-packages/pypsrp/messages.py", line 208, in unpack
    message_data = serializer.deserialize(message_data)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/serializer.py", line 350, in deserialize
    obj = self._deserialize_dynamic_obj(element, metadata)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/serializer.py", line 685, in _deserialize_dynamic_obj
    value = self.deserialize(adapted_property, clear=False)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/serializer.py", line 228, in deserialize
    return unpack_function(element)
  File "/usr/local/lib/python3.9/site-packages/pypsrp/serializer.py", line 224, in <lambda>
    "Ref": lambda d: self.obj[d.attrib["RefId"]],
KeyError: '18'

Process finished with exit code 1

Collected logs here: pypsrp.xml.log