Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: got an unexpected keyword argument 'origin' #190

Open
JobaDiniz opened this issue Dec 19, 2023 · 0 comments
Open

Error: got an unexpected keyword argument 'origin' #190

JobaDiniz opened this issue Dec 19, 2023 · 0 comments

Comments

@JobaDiniz
Copy link

JobaDiniz commented Dec 19, 2023

I come from dotnet - new to python - and I was struggling to find the best way to serialize/deserialize python classes, until I found this library. It should be simple as this library does it, so thank you for that.

Now into my issue, I'm trying to deserialize the following JSON:

{
  "id": "28aafb64-e081-4b98-8e3d-56d0376ea078",
  "data": {
    "tab": {
      "active": true,
      "audible": false,
      "autoDiscardable": true,
      "discarded": false,
      "favIconUrl": "https://opensource-demo.orangehrmlive.com/web/dist/favicon.ico?v=1689053487449",
      "groupId": -1,
      "height": 911,
      "highlighted": true,
      "id": 1980783810,
      "incognito": false,
      "index": 1,
      "mutedInfo": {
        "muted": false
      },
      "pinned": false,
      "selected": true,
      "status": "complete",
      "title": "OrangeHRM",
      "url": "https://opensource-demo.orangehrmlive.com/web/index.php/auth/login",
      "width": 1920,
      "windowId": 1980783809
    }
  }
}

Into these classes:

class BrowserTab:
    def __init__(self, id: Optional[str], index: int, active: bool, url: Optional[str], title: Optional[str]) -> None:
        self.id = id
        self.index = index
        self.active = active
        self.url = url
        self.title = title

class ConnectionResponse:
    def __init__(self, tab: BrowserTab, pageAnalysis: object) -> None:
        self.tab = tab
        self.pageAnalysis = pageAnalysis

TResponse = TypeVar('TResponse')
class Response(Generic[TResponse]):
    def __init__(self, id: str, error: object, data: TResponse) -> None:
        self.id = id
        self.error = error
        self.data = data

The code to deserialize is: jsons.loads(response, commands.Response[commands.ConnectionResponse])

This gives me an error:

jsons.exceptions.DeserializationError: Could not deserialize value "{'id': '28aafb64-e081-4b98-8e3d-56d0376ea078', 'data': {'tab': {'active': True, 'audible': False, 'autoDiscardable': True, 'discarded': False, 'favIconUrl': 'https://opensource-demo.orangehrmlive.com/web/dist/favicon.ico?v=1689053487449', 'groupId': -1, 'height': 911, 'highlighted': True, 'id': 1980783810, 'incognito': False, 'index': 1, 'mutedInfo': {'muted': False}, 'pinned': False, 'selected': True, 'status': 'complete', 'title': 'OrangeHRM', 'url': 'https://opensource-demo.orangehrmlive.com/web/index.php/auth/login', 'width': 1920, 'windowId': 1980783809}}}" into "server.commands.Response". 
Response.__init__() got an unexpected keyword argument 'origin'

Where does this "origin" coming from?

UPDATE
Also, I don't know the difference between jsons.load and jsons.loads. So when trying load (singular), I got different error:

raise DeserializationError(message, json_obj, cls) from err
jsons.exceptions.DeserializationError: Could not deserialize value "{"id":"ca9a6637-243f-435f-920f-f163d52cc426","data":{"tab":{"active":true,"audible":false,"autoDiscardable":true,"discarded":false,"favIconUrl":"https://opensource-demo.orangehrmlive.com/web/dist/favicon.ico?v=1689053487449","groupId":-1,"height":911,"highlighted":true,"id":1980784105,"incognito":false,"index":1,"mutedInfo":{"muted":false},"pinned":false,"selected":true,"status":"complete","title":"OrangeHRM","url":"https://opensource-demo.orangehrmlive.com/web/index.php/auth/login","width":1920,"windowId":1980783809}}}" into "server.commands.Response". 
string indices must be integers, not 'str'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant