Merge remote-tracking branch 'origin/master'

This commit is contained in:
marco
2020-04-23 20:22:51 +02:00
8 changed files with 123 additions and 21 deletions

View File

@@ -6,6 +6,7 @@
import traceback
from platformcode import logger
from inspect import stack
try:
import json
@@ -43,6 +44,7 @@ def load(*args, **kwargs):
except:
logger.error("**NOT** able to load the JSON")
logger.error(traceback.format_exc())
logger.error('ERROR STACK ' + str(stack()[1][3]))
value = {}
return value

View File

@@ -826,7 +826,7 @@ class Tmdb(object):
self.busqueda_texto = re.sub('\[\\\?(B|I|COLOR)\s?[^\]]*\]', '', self.texto_buscado).strip()
self.busqueda_tipo = kwargs.get('tipo', '')
self.busqueda_idioma = kwargs.get('idioma_busqueda', def_lang)
self.busqueda_include_adult = kwargs.get('include_adult', False)
# self.busqueda_include_adult = kwargs.get('include_adult', False)
self.busqueda_year = kwargs.get('year', '')
self.busqueda_filtro = kwargs.get('filtro', {})
self.discover = kwargs.get('discover', {})
@@ -978,7 +978,7 @@ class Tmdb(object):
# &include_adult=false&page=1
url = ('http://api.themoviedb.org/3/search/%s?api_key=a1ab8b8669da03637a4b98fa39c39228&query=%s&language=%s'
'&include_adult=%s&page=%s' % (self.busqueda_tipo, text_quote,
self.busqueda_idioma, self.busqueda_include_adult, page))
self.busqueda_idioma, True, page))
if self.busqueda_year:
url += '&year=%s' % self.busqueda_year

View File

@@ -54,7 +54,7 @@ except ImportError:
# ------------------------------------------------------------------------------- #
__version__ = '1.2.32'
__version__ = '1.2.34'
# ------------------------------------------------------------------------------- #
@@ -102,6 +102,7 @@ class CloudScraper(Session):
self.debug = kwargs.pop('debug', False)
self.delay = kwargs.pop('delay', None)
self.cipherSuite = kwargs.pop('cipherSuite', None)
self.ssl_context = kwargs.pop('ssl_context', None)
self.interpreter = kwargs.pop('interpreter', 'native')
self.recaptcha = kwargs.pop('recaptcha', {})
self.allow_brotli = kwargs.pop(
@@ -134,7 +135,8 @@ class CloudScraper(Session):
self.mount(
'https://',
CipherSuiteAdapter(
cipherSuite=self.cipherSuite
cipherSuite=self.cipherSuite,
ssl_context=self.ssl_context
)
)
@@ -253,7 +255,7 @@ class CloudScraper(Session):
resp.headers.get('Server', '').startswith('cloudflare')
and resp.status_code in [429, 503]
and re.search(
r'action="/.*?__cf_chl_jschl_tk__=\S+".*?name="jschl_vc"\svalue=.*?',
r'<form id="challenge-form" action="/.*?__cf_chl_jschl_tk__=\S+"',
resp.text,
re.M | re.DOTALL
)
@@ -340,12 +342,11 @@ class CloudScraper(Session):
"Cloudflare IUAM detected, unfortunately we can't extract the parameters correctly."
)
payload = OrderedDict(
re.findall(
r'name="(r|jschl_vc|pass)"\svalue="(.*?)"',
formPayload['form']
)
)
payload = OrderedDict()
for challengeParam in re.findall(r'<input\s(.*?)>', formPayload['form']):
inputPayload = dict(re.findall(r'(\S+)="(\S+)"', challengeParam))
if inputPayload.get('name') in ['r', 'jschl_vc', 'pass']:
payload.update({inputPayload['name']: inputPayload['value']})
except AttributeError:
self.simpleException(

View File

@@ -36,6 +36,12 @@ class CloudflareIUAMError(CloudflareException):
"""
class CloudflareSolveError(CloudflareException):
"""
Raise an error when issue with solving Cloudflare challenge
"""
class CloudflareReCaptchaError(CloudflareException):
"""
Raise an error for problem extracting reCaptcha paramters

79
lib/cloudscraper/help.py Normal file
View File

@@ -0,0 +1,79 @@
import json
import platform
import requests
import ssl
import sys
import urllib3
from collections import OrderedDict
from . import __version__ as cloudscraper_version
# ------------------------------------------------------------------------------- #
def getPossibleCiphers():
try:
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
context.set_ciphers('ALL')
return sorted([cipher['name'] for cipher in context.get_ciphers()])
except AttributeError:
return 'get_ciphers() is unsupported'
# ------------------------------------------------------------------------------- #
def _pythonVersion():
interpreter = platform.python_implementation()
interpreter_version = platform.python_version()
if interpreter == 'PyPy':
interpreter_version = '{}.{}.{}'.format(
sys.pypy_version_info.major,
sys.pypy_version_info.minor,
sys.pypy_version_info.micro
)
if sys.pypy_version_info.releaselevel != 'final':
interpreter_version = '{}{}'.format(
interpreter_version,
sys.pypy_version_info.releaselevel
)
return {
'name': interpreter,
'version': interpreter_version
}
# ------------------------------------------------------------------------------- #
def systemInfo():
try:
platform_info = {
'system': platform.system(),
'release': platform.release(),
}
except IOError:
platform_info = {
'system': 'Unknown',
'release': 'Unknown',
}
return OrderedDict([
('platform', platform_info),
('interpreter', _pythonVersion()),
('cloudscraper', cloudscraper_version),
('requests', requests.__version__),
('urllib3', urllib3.__version__),
('OpenSSL', OrderedDict(
[
('version', ssl.OPENSSL_VERSION),
('ciphers', getPossibleCiphers())
]
))
])
# ------------------------------------------------------------------------------- #
if __name__ == '__main__':
print(json.dumps(systemInfo(), indent=4))

View File

@@ -2,6 +2,8 @@ import sys
import logging
import abc
from ..exceptions import CloudflareSolveError
if sys.version_info >= (3, 4):
ABC = abc.ABC # noqa
else:
@@ -10,7 +12,6 @@ else:
# ------------------------------------------------------------------------------- #
interpreters = {}
BUG_REPORT = 'Cloudflare may have changed their technique, or there may be a bug in the script.'
# ------------------------------------------------------------------------------- #
@@ -50,5 +51,6 @@ class JavaScriptInterpreter(ABC):
try:
return float(self.eval(body, domain))
except Exception:
logging.error('Error executing Cloudflare IUAM Javascript. {}'.format(BUG_REPORT))
raise
raise CloudflareSolveError(
'Error trying to solve Cloudflare IUAM Javascript, they may have changed their technique.'
)

View File

@@ -1,5 +1,4 @@
from __future__ import absolute_import
from ..exceptions import (
reCaptchaParameter,
reCaptchaTimeout,
@@ -19,12 +18,19 @@ except ImportError:
"pip install python-anticaptcha or https://github.com/ad-m/python-anticaptcha/"
)
import sys
from . import reCaptcha
class captchaSolver(reCaptcha):
def __init__(self):
if sys.modules['python_anticaptcha'].__version__ < 0.6:
raise ImportError(
"Please upgrade the python module 'python_anticaptcha' via "
"pip install -U python-anticaptcha or https://github.com/ad-m/python-anticaptcha/"
)
super(captchaSolver, self).__init__('anticaptcha')
# ------------------------------------------------------------------------------- #
@@ -51,7 +57,7 @@ class captchaSolver(reCaptcha):
"https://github.com/ad-m/python-anticaptcha/tree/hcaptcha"
)
job = client.createTaskSmee(task)
job = client.createTaskSmee(task, timeout=180)
try:
job.join(maximum_time=180)

View File

@@ -2,7 +2,6 @@
"chrome": {
"default_headers": {
"User-Agent": null,
"DNT": "1",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br"
@@ -17,9 +16,13 @@
"ECDHE-RSA-AES256-GCM-SHA384",
"ECDHE-ECDSA-CHACHA20-POLY1305",
"ECDHE-RSA-CHACHA20-POLY1305",
"ECDHE-RSA-AES128-SHA",
"ECDHE-RSA-AES256-SHA",
"AES128-GCM-SHA256",
"AES256-GCM-SHA384",
"AES128-SHA"
"AES128-SHA",
"AES256-SHA",
"DES-CBC3-SHA"
],
"releases": {
"Chrome/50.0.0.0": {
@@ -12807,8 +12810,7 @@
"User-Agent": null,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"DNT": "1"
"Accept-Encoding": "gzip, deflate, br"
},
"cipherSuite": [
"TLS_AES_128_GCM_SHA256",
@@ -12822,9 +12824,13 @@
"ECDHE-RSA-AES256-GCM-SHA384",
"ECDHE-ECDSA-AES256-SHA",
"ECDHE-ECDSA-AES128-SHA",
"ECDHE-RSA-AES128-SHA",
"ECDHE-RSA-AES256-SHA",
"DHE-RSA-AES128-SHA",
"DHE-RSA-AES256-SHA",
"AES128-SHA"
"AES128-SHA",
"AES256-SHA",
"DES-CBC3-SHA"
],
"releases": {
"Firefox/50.0": {