0

I'm currently facing a problem with window.js_obj I have a JSObject obtain through an API and jQuery but when I try to convert the gotten JSObject into a proper Python Dict, it seems like there is no module called js_obj into window. Here is what I wrote to convert the thing:

userInfo_request = window.js_obj.to_dict(userInfo_request)

(userInfo_request is my variable containing the JSObject as stated when I input

print(type(userInfo_request))
<class 'JSObject'>

The error that I get in my browser's console is:

Traceback (most recent call last):
  module __main__ line 31
    userInfo_request = window.js_obj.to_dict(userInfo_request)
AttributeError: no attribute js_obj for [object Window]

If someone could help me it would be super cool Thanks in advance

I'm using Python 3 and Brython 3.8.7 (the latest version)

2 Answers2

1

You can use:

dir(window)
# Or
hasattr(window, 'js_obj')

to check if the window object has the js_obj attribute or not at the runtime.

shayan rok rok
  • 494
  • 3
  • 12
1

I understood the problem. In fact, I think it was changed in an update (but we should change the documentations) and the js_obj.to_dict got changed into JSObject.to_dict in the module “javascript” instead of “window”