question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python2 vs Python3

See original GitHub issue

Hi @PiotrDabkowski ,

The following works in python2… however we get an error when using python3

  File "/usr/local/lib/python3.5/dist-packages/js2py/base.py", line 547, in to_primitive
    return self.default_value(hint)
  File "/usr/local/lib/python3.5/dist-packages/js2py/base.py", line 455, in default_value
    'Cannot convert object to primitive value')
js2py.internals.simplex.JsException: TypeError: Cannot convert object to primitive value

test code is as follows…

import js2py
import base64

def atob(s):
   return base64.b64decode('{}'.format(s))

context = js2py.EvalJs({ "atob": atob })
context.eval(
"""
var t = "www3.hd.today";
function italics (str) { return '<i>' + this + '</i>'; };
var document = {
   getElementById: function () {
      return {'innerHTML': '+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(+[])+(!+[]+true+true))/+((!+[]+true+true+[])+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true)+(!+[]+true+true+true+true)+(+[])+(!+[]+true+true+true+true+true))'};
      }
};
var s,t,o,p,b,r,e,a,k,i,n,g,f, zEANQPm={"UjYfQbvVqXn":+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(+[])+(!+[]+true+true))/+((!+[]+true+true+true+true+true+true+[])+(!+[]+true)+(+[])+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true)+(!+[]+true)+(!+[]+true+true)+(!+[]+true+true))};        ;zEANQPm.UjYfQbvVqXn-=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true))/+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true+true));zEANQPm.UjYfQbvVqXn-=+((!+[]+true+true+true+true+true+true+true+true+[])+(!+[]+true+true+true)+(+true)+(+[])+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(+true))/+((!+[]+true+[])+(!+[]+true)+(!+[]+true)+(+[])+(!+[]+true)+(!+[]+true+true+true+true+true+true)+(+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true));zEANQPm.UjYfQbvVqXn*=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(+true))/+((+true+[])+(+true)+(!+[]+true)+(+true)+(!+[]+true+true+true)+(+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true));zEANQPm.UjYfQbvVqXn+=+((!+[]+true+true+true+true+true+true+true+true+[])+(!+[]+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true)+(!+[]+true+true))/+((!+[]+true+true+true+true+true+[])+(!+[]+true)+(!+[]+true+true+true)+(+[])+(!+[]+true+true+true+true+true)+(+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true));zEANQPm.UjYfQbvVqXn*=+((!+[]+true+true+true+true+true+true+true+true+[])+(!+[]+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true)+(!+[]+true+true))/+((!+[]+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true)+(+[])+(+true)+(!+[]+true+true+true+true+true));zEANQPm.UjYfQbvVqXn*=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true))/+((!+[]+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true+true+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true+true));zEANQPm.UjYfQbvVqXn+=+((!+[]+true+true+true+true+true+true+true+[])+(+true)+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(+[])+(!+[]+true+true+true)+(!+[]+true)+(!+[]+true+true+true+true)+(!+[]+true+true))/+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true)+(!+[]+true)+(!+[]+true)+(!+[]+true+true+true+true+true+true+true+true)+(+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true)+(!+[]+true+true+true+true+true));zEANQPm.UjYfQbvVqXn+=+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true)+(+[])+(+[])+(!+[]+true+true)+(!+[]+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true+true+true+true))/+((!+[]+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true)+(!+[]+true)+(+[])+(!+[]+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true));zEANQPm.UjYfQbvVqXn+=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(+[])+(!+[]+true+true))/+((!+[]+true+true+true+true+true+true+true+true+[])+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true)+(+[])+(!+[]+true+true+true+true+true+true+true)+(+true));zEANQPm.UjYfQbvVqXn-=+((!+[]+true+true+true+true+true+true+true+true+[])+(!+[]+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true)+(!+[]+true+true))/+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(+[])+(!+[]+true)+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true)+(!+[]+true)+(!+[]+true+true+true+true));zEANQPm.UjYfQbvVqXn*=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true))/(+(+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true)+(+true)+(!+[]+true+true+true)+(!+[]+true+true)+(+true)+(!+[]+true+true)+(!+[]+true+true+true)+(+true)))+(function(p){return eval("t"+"."+"c"+"h"+"a"+"r"+"C"+"o"+"d"+"e"+"A"+"t"+"("+p+")")}(+((!+[]+true+true+true+[])))));zEANQPm.UjYfQbvVqXn-=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true))/+((!+[]+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true+true+true)+(+true)+(+true)+(+[])+(!+[]+true+true+true));zEANQPm.UjYfQbvVqXn+=function(p){var p = eval(eval(atob("ZG9jdW1l")+"n"+"t"+"."+"g"+"e"+"t"+"Element"+"B"+"y"+"Id("+"k"+")."+atob("aW5uZXJIVE1M"))); return +(p)}();zEANQPm.UjYfQbvVqXn-=+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true)+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true)+(+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true)+(+true))/+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(+[])+(+[])+(!+[]+true+true+true+true+true+true+true)+(+[])+(!+[]+true+true+true+true+true+true)+(!+[]+true+true+true+true+true)+(!+[]+true+true+true+true+true+true));zEANQPm.UjYfQbvVqXn+=+((!+[]+true+true+true+true+true+true+[])+(!+[]+true+true+true+true+true+true+true+true)+(!+[]+true+true+true+true+true+true)+(+[])+(+[])+(!+[]+true+true)+(!+[]+true+true+true)+(!+[]+true+true)+(!+[]+true+true+true+true+true+true))/+((!+[]+true+true+true+true+true+true+true+[])+(!+[]+true+true+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true)+(!+[]+true+true+true+true+true+true+true)+(!+[]+true+true+true+true)+(!+[]+true+true+true+true+true+true)+(+true)+(!+[]+true+true+true+true));(+zEANQPm.UjYfQbvVqXn).toFixed(10)
"""
)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Apr 3, 2019

Ah, okay

import js2py
import base64

def atob(s):
   return base64.b64decode('{}'.format(s)).decode('utf-8')

context = js2py.EvalJs({ "atob": atob });
1reaction
PiotrDabkowskicommented, Apr 3, 2019

The reason is your atob function that returns the bytes instead of string. The bytes are converted to PyJsObjectWrapper which cannot be converted to a primitive value, hence the error 😃

I guess it should be converted to native Js type just like string and unicode types, but this is done currently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 2 Vs. Python 3: Key Difference Between 2.x & 3.x
Python 3 syntax is simpler and easily understandable whereas Python 2 syntax is comparatively difficult to understand. · Python 3 default storing ...
Read more >
Important differences between Python 2.x and Python 3.x with ...
This is the most well-known change. In this, the print keyword in Python 2.x is replaced by the print() function in Python 3.x....
Read more >
A 2020 Guide to Python 2 vs Python 3 - Career Karma
Python 3 is more in-demand and includes a typing system. Python 2 is outdated and uses an older syntax for the print function....
Read more >
Python 2 vs Python 3: The Key Differences - Great Learning
Python 2 was released in the year 2000 whereas Python 3 was released in the year 2008. ... In Python 2, print is...
Read more >
Python 2 vs 3: Everything You Need to Know - DataCamp
Some of the major changes in Python 3 include changing the print declaration to a built-in function, improved integer division, and improved Unicode...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found