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

Responses have changed. #18

Closed
Ghxst opened this issue Mar 18, 2020 · 2 comments
Closed

Responses have changed. #18

Ghxst opened this issue Mar 18, 2020 · 2 comments

Comments

@Ghxst
Copy link
Contributor

Ghxst commented Mar 18, 2020

The contents of the JSON responses returned by chrome need to be accessed via the result key.

Currently the return statements created by the generator (example: return Node.from_json(json['root'])) will raise a KeyError.
To fix this, return statements should be changed to Node.from_json(json['result']['root'])

Can you point me to what part of the generator code handles this? I can fix it and create a pull request.

@mehaase
Copy link
Contributor

mehaase commented Mar 19, 2020

This actually hasn't changed. The result key is part of the JSON RPC-ish protocol that Chrome speaks. This project assumes that you implement the RPC framing in a higher level library (but see #12 as a potential change there), so at that higher level you would unpack the response, check for errors, and if everything was okay, then you'd convert the json['result'] to a native Python CDP type.

For example, see https://github.com/HyperionGray/trio-chrome-devtools-protocol/blob/0.5.0/trio_cdp/__init__.py#L139.

I don't think we could add the ['result'] in this project right now even if we wanted to, because from_json() is used recursively, i.e. objects will call this to create objects out of subdictionaries, and those subdictionaries won't have a result key in them.

@Ghxst
Copy link
Contributor Author

Ghxst commented Mar 20, 2020

Oo ok that makes sense now, thank you for the detailed explanation!
I will close this issue. :)

@Ghxst Ghxst closed this as completed Mar 20, 2020
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

2 participants