aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/cloudscraper/interpreters/nodejs.py
diff options
context:
space:
mode:
authorLouis Vézina <[email protected]>2020-08-15 08:28:01 -0400
committerLouis Vézina <[email protected]>2020-08-15 08:28:01 -0400
commitf7c85f09e011bfbd032e03e18fd869570383d0ab (patch)
tree35d77935f6e2af899bd27c411808d9053cf321ca /libs/cloudscraper/interpreters/nodejs.py
parentb86cd94d3e237726f4576ae8a53700a113c223d2 (diff)
parented7eae6b97d632dff9ffc5b8d998656d074bbcb0 (diff)
downloadbazarr-f7c85f09e011bfbd032e03e18fd869570383d0ab.tar.gz
bazarr-f7c85f09e011bfbd032e03e18fd869570383d0ab.zip
Merge branch 'development'v0.9.0.2
Diffstat (limited to 'libs/cloudscraper/interpreters/nodejs.py')
-rw-r--r--libs/cloudscraper/interpreters/nodejs.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/libs/cloudscraper/interpreters/nodejs.py b/libs/cloudscraper/interpreters/nodejs.py
index bafab288d..28a375984 100644
--- a/libs/cloudscraper/interpreters/nodejs.py
+++ b/libs/cloudscraper/interpreters/nodejs.py
@@ -1,23 +1,22 @@
import base64
+import logging
import subprocess
-import sys
from . import JavaScriptInterpreter
-from .encapsulated import template
-# ------------------------------------------------------------------------------- #
+##########################################################################################################################################################
+BUG_REPORT = 'Cloudflare may have changed their technique, or there may be a bug in the script.'
+
+##########################################################################################################################################################
-class ChallengeInterpreter(JavaScriptInterpreter):
- # ------------------------------------------------------------------------------- #
+class ChallengeInterpreter(JavaScriptInterpreter):
def __init__(self):
super(ChallengeInterpreter, self).__init__('nodejs')
- # ------------------------------------------------------------------------------- #
-
- def eval(self, body, domain):
+ def eval(self, jsEnv, js):
try:
js = 'var atob = function(str) {return Buffer.from(str, "base64").toString("binary");};' \
'var challenge = atob("%s");' \
@@ -25,25 +24,23 @@ class ChallengeInterpreter(JavaScriptInterpreter):
'var options = {filename: "iuam-challenge.js", timeout: 4000};' \
'var answer = require("vm").runInNewContext(challenge, context, options);' \
'process.stdout.write(String(answer));' \
- % base64.b64encode(template(body, domain).encode('UTF-8')).decode('ascii')
+ % base64.b64encode('{}{}'.format(jsEnv, js).encode('UTF-8')).decode('ascii')
return subprocess.check_output(['node', '-e', js])
except OSError as e:
if e.errno == 2:
raise EnvironmentError(
- 'Missing Node.js runtime. Node is required and must be in the PATH (check with `node -v`).\n\n'
- 'Your Node binary may be called `nodejs` rather than `node`, '
- 'in which case you may need to run `apt-get install nodejs-legacy` on some Debian-based systems.\n\n'
- '(Please read the cloudscraper README\'s Dependencies section: '
- 'https://github.com/VeNoMouS/cloudscraper#dependencies.)'
+ 'Missing Node.js runtime. Node is required and must be in the PATH (check with `node -v`). Your Node binary may be called `nodejs` rather than `node`, '
+ 'in which case you may need to run `apt-get install nodejs-legacy` on some Debian-based systems. (Please read the cloudscraper'
+ ' README\'s Dependencies section: https://github.com/VeNoMouS/cloudscraper#dependencies.'
)
raise
except Exception:
- sys.tracebacklimit = 0
- raise RuntimeError('Error executing Cloudflare IUAM Javascript in nodejs')
+ logging.error('Error executing Cloudflare IUAM Javascript. %s' % BUG_REPORT)
+ raise
+ pass
-# ------------------------------------------------------------------------------- #
ChallengeInterpreter()