cleitonleonel/pyquotex

Error on Login

stephenpaulraj opened this issue · 15 comments

File session.json is missing on this repo.
Can yo help me in solving this.

Autenticando usuário...
HTTP Error 403: Forbidden, Retrying in 3 seconds...
HTTP Error 403: Forbidden, Retrying in 6 seconds...
HTTP Error 403: Forbidden, Retrying in 12 seconds...

--- request header ---
GET /socket.io/?EIO=3&transport=websocket HTTP/1.1
Upgrade: websocket
Host: ws2.qxbroker.com
Origin: https://qxbroker.com
Connection: Upgrade
Accept: /
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: NyTCcISxt4pU1zWrLjyqZg==
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36


--- response header ---
HTTP/1.1 403 Forbidden
Date: Sat, 18 Mar 2023 19:26:31 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Permissions-Policy: accelerometer=(),autoplay=(),camera=(),clipboard-read=(),clipboard-write=(),fullscreen=(),geolocation=(),gyroscope=(),hid=(),interest-cohort=(),magnetometer=(),microphone=(),payment=(),publickey-credentials-get=(),screen-wake-lock=(),serial=(),sync-xhr=(),usb=()
Referrer-Policy: same-origin
X-Frame-Options: SAMEORIGIN
Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Set-Cookie: __cf_bm=NyKxBG9A7ldgV2B3CfFXChqbd4y3cAmszxWkBWvIsY0-1679167591-0-AeXhDjAH2LL7vKNQ6pETVRr2P+XxxLDN/U18PXQZK8z6c7uFXTH+SAqnEips0+bO79K8R/tbjMlWY27m0KTx0YI=; path=/; expires=Sat, 18-Mar-23 19:56:31 GMT; domain=.qxbroker.com; HttpOnly; Secure; SameSite=None
Server-Timing: cf-q-config;dur=6.9999950937927e-06
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 7a9fde25ddda52af-CCU
Content-Encoding: gzip

Handshake status 403 Forbidden - goodbye
False Handshake status 403 Forbidden

Traceback (most recent call last):
File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/main.py", line 154, in
login()
File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/main.py", line 9, in login
check_connect, message = client.connect()
File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/quotexapi/stable_api.py", line 139, in connect
os.remove("session.json")
FileNotFoundError: [Errno 2] No such file or directory: 'session.json'

False Handshake status 403 Forbidden

Unauthorized, this error is due to a block by cloudflare for login automation, for some reason they still identify the automated access, try to access with a new account or update the data sent in the header, such as the referer field.

Eu também estou com o mesmo erro

Eu também estou com o mesmo erro

Então esse erro é relacionado ao bloqueio feito pela cloudflare como mencionei acima, ainda não consegui contornar isso, aceito contribuições e ideias para resolver esse imbróglio.

File session.json is missing on this repo. Can yo help me in solving this.

Autenticando usuário... HTTP Error 403: Forbidden, Retrying in 3 seconds... HTTP Error 403: Forbidden, Retrying in 6 seconds... HTTP Error 403: Forbidden, Retrying in 12 seconds...

--- request header --- GET /socket.io/?EIO=3&transport=websocket HTTP/1.1 Upgrade: websocket Host: ws2.qxbroker.com Origin: https://qxbroker.com Connection: Upgrade Accept: / Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate, br Sec-WebSocket-Version: 13 Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: NyTCcISxt4pU1zWrLjyqZg== Pragma: no-cache Cache-Control: no-cache User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36

--- response header ---

HTTP/1.1 403 Forbidden
Date: Sat, 18 Mar 2023 19:26:31 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Permissions-Policy: accelerometer=(),autoplay=(),camera=(),clipboard-read=(),clipboard-write=(),fullscreen=(),geolocation=(),gyroscope=(),hid=(),interest-cohort=(),magnetometer=(),microphone=(),payment=(),publickey-credentials-get=(),screen-wake-lock=(),serial=(),sync-xhr=(),usb=()
Referrer-Policy: same-origin
X-Frame-Options: SAMEORIGIN
Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Set-Cookie: __cf_bm=NyKxBG9A7ldgV2B3CfFXChqbd4y3cAmszxWkBWvIsY0-1679167591-0-AeXhDjAH2LL7vKNQ6pETVRr2P+XxxLDN/U18PXQZK8z6c7uFXTH+SAqnEips0+bO79K8R/tbjMlWY27m0KTx0YI=; path=/; expires=Sat, 18-Mar-23 19:56:31 GMT; domain=.qxbroker.com; HttpOnly; Secure; SameSite=None
Server-Timing: cf-q-config;dur=6.9999950937927e-06
Vary: Accept-Encoding
Server: cloudflare
CF-RAY: 7a9fde25ddda52af-CCU
Content-Encoding: gzip
Handshake status 403 Forbidden - goodbye False Handshake status 403 Forbidden

Traceback (most recent call last): File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/main.py", line 154, in login() File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/main.py", line 9, in login check_connect, message = client.connect() File "/Users/stephenpaulraj/PycharmProjects/quotex-api-py/quotexapi/stable_api.py", line 139, in connect os.remove("session.json") FileNotFoundError: [Errno 2] No such file or directory: 'session.json'

In the most recent tests I did, I noticed that the mentioned error occurs a lot when using a more recent version of python, such as version 3.10, however the same does not occur in older versions of python, here I do not receive this error due to the fact that using python 3.8, of course sometimes cloudflare gives me a block, but most of the time everything works fine.
So the suggestion is to use python 3.8 ...

Eu também estou com o mesmo erro

Nos mais recentes testes que fiz, percebi que o erro mencionado ocorre demasiadamente quando se usa uma versão mais recente do python, como a versão 3.10, porém o mesmo não ocorre em versões mais antigas do python, aqui não recebo esse erro devido ao fato de usar python 3.8, claro as vezes a cloudflare me da um block, mas na maioria das vezes tudo ocorre muito bem.
Sendo assim a sugestão é que use python 3.8 ...

Olá, mesmo utlizando o python 3.8 e tentando com outras contas, tenho o mesmo bloqueio da Cloudfare. Com você o bloqueio voltou a acontecer?

Olá, mesmo utlizando o python 3.8 e tentando com outras contas, tenho o mesmo bloqueio da Cloudfare. Com você o bloqueio voltou a acontecer?

Pior que sim, voltou depois de uns dias usando nesse esquema, cloudflare tá muito má kkkk, mas sigo na busca de resolver esse B.O e aceito sugestões, caso alguém tenha uma solução basta fazer um commit ...

Segun la documentacion
Login by email/password
!!! not support now !!!

La uniica forma es por Login by ssid, que se realiza con selenium

Ya estoy corrigiendo pero no me termina de ejecutar

#python

import json
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--disable-extensions')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--unhandledPromptBehavior=accept')
options.add_argument('--pageLoadStrategy=normal')
capabilities = DesiredCapabilities.CHROME.copy()
capabilities['goog:loggingPrefs'] = {'performance': 'ALL'}

driver = webdriver.Chrome(options=options, desired_capabilities=capabilities)
driver.delete_all_cookies()
driver.get("https://qxbroker.com/en/sign-in/")
ssid = None
while True:
if ssid != None:
break
for entry in driver.get_log('performance'):
try:
message = json.loads(entry['message'])['message']
if 'Network.responseReceived' in message['method']:
response = message['params']['response']
headers = response['headers']
for header in headers:
if header['name'] == 'authorization':
ssid = header['value']
print(ssid)
except:
pass

Segun la documentacion Login by email/password !!! not support now !!!

La uniica forma es por Login by ssid, que se realiza con selenium

Ya estoy corrigiendo pero no me termina de ejecutar

#python

import json from selenium.webdriver.chrome.service import Service as ChromeService from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.chrome.service import Service from selenium import webdriver

options = webdriver.ChromeOptions() options.add_argument('--disable-extensions') options.add_argument('--disable-infobars') options.add_argument('--disable-dev-shm-usage') options.add_argument('--no-sandbox') options.add_argument('--unhandledPromptBehavior=accept') options.add_argument('--pageLoadStrategy=normal') capabilities = DesiredCapabilities.CHROME.copy() capabilities['goog:loggingPrefs'] = {'performance': 'ALL'}

driver = webdriver.Chrome(options=options, desired_capabilities=capabilities) driver.delete_all_cookies() driver.get("https://qxbroker.com/en/sign-in/") ssid = None while True: if ssid != None: break for entry in driver.get_log('performance'): try: message = json.loads(entry['message'])['message'] if 'Network.responseReceived' in message['method']: response = message['params']['response'] headers = response['headers'] for header in headers: if header['name'] == 'authorization': ssid = header['value'] print(ssid) except: pass

Bueno, antes que nada, gracias por su contribución, pero si no me equivoco, este mismo fragmento de código está documentado en la API de Anson, utilicé la documentación en sí https://lu-yi-hsun.github.io/quotexapi/ #get-ssid-by-selenium para intentar crear esta api, aunque aún me falta algo de conocimiento hasta que logré replicar algunas funciones, esta sin embargo es una de las más complicadas, así que siguiendo algunos consejos terminé creando una forma de obtener el ssid y las cookies usando dramaturgo, pero es posible que aún no funcione correctamente...
Estoy agradecido por cualquier otra sugerencia o consejo y gracias.

Puedes actualizar tu repositorio para ver tu avance, yo igual tengo algo avanzado pero me gustaría ver lo tuyo para ver si vamos por el mismo camino.

Guys, Try this. Using undetected chrome to by pass cloudflare and saves the cookies, ssid and user-agent in session.json, later you can use it for connecting websockets. I have a simple implementation, i will put it on separate repo
`from pathlib import Path

import time

import json
import re
import os
import certifi
import undetected_chromedriver as uc
from bs4 import BeautifulSoup
import ssl
import logging
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

cert_path = certifi.where()
os.environ['SSL_CERT_FILE'] = cert_path
os.environ['WEBSOCKET_CLIENT_CA_BUNDLE'] = cert_path
cacert = os.environ.get('WEBSOCKET_CLIENT_CA_BUNDLE')

ssl._create_default_https_context = ssl._create_unverified_context
logger = logging.getLogger(name)

def login_generate_session_raw():
"""Log in to the website and extract the session information.

Returns:
    A dictionary containing the session information, including cookies,
    ssid, and user agent.
"""
driver = uc.Chrome()
driver.maximize_window()
time.sleep(5)
driver.get('https://qxbroker.com/en/sign-in')
soup = BeautifulSoup(driver.page_source, 'html.parser')
username = driver.find_element(By.XPATH, "/html/body/bdi/div[1]/div/div[2]/div[3]/form/div[1]/input")
password = driver.find_element(By.XPATH, "/html/body/bdi/div[1]/div/div[2]/div[3]/form/div[2]/input")
driver.implicitly_wait(10)
username.send_keys("email@gmail.com")
password.send_keys("password")
time.sleep(5)
token = soup.find("input", {"name": "_token"})["value"]
cookieListSign = driver.get_cookies()
time.sleep(5)
driver.find_element(By.XPATH, "/html/body/bdi/div[1]/div/div[2]/div[3]/form/button").click()
time.sleep(5)

currentUrl = driver.current_url
user_agent = driver.execute_script("return navigator.userAgent;")

if currentUrl == 'https://qxbroker.com/en/trade':
    soup = BeautifulSoup(driver.page_source, 'html.parser')
    script = soup.find_all("script", {"type": "text/javascript"})[1].get_text()
    match = re.sub("window.settings = ", "", script.strip().replace(";", ""))
    ssid = json.loads(match).get("token")
    print('SSID is : ' + ssid)
    cookieListTrade = driver.get_cookies()
    fileToWrite = {"cookiesTrade": cookieListTrade, "ssid": ssid, "user-agent": user_agent}
    print(f"fileToWrite: {fileToWrite}")
    driver.close()
    # Convert
    data = fileToWrite
    cookies = ""
    for cookie in data["cookiesTrade"]:
        if cookie["name"] == "__cf_bm":
            cookies += f'{cookie["name"]}={cookie["value"]}; '
        elif cookie["name"] == "lang":
            cookies += f'{cookie["name"]}={cookie["value"]}; '
        elif cookie["name"] == "laravel_session":
            cookies += f'{cookie["name"]}={cookie["value"]}; '
    final = convert_format(cookies)
    cook = {
        "cookies": final,
        "ssid": data['ssid'],
        "user_agent": data['user-agent']
    }
    finalData = {"cookies": final, "ssid": data['ssid'], "user_agent": data['user-agent']}
    print(f"returnData: {finalData}")
    output_file = Path("session.json")
    output_file.parent.mkdir(exist_ok=True, parents=True)
    output_file.write_text(
        json.dumps(finalData, indent=4)
    )
    return finalData

def convert_format(input_str):
cookies = input_str.split('; ')
lang_cookie = ''
laravel_session_cookie = ''
for cookie in cookies:
if cookie.startswith('lang='):
lang_cookie = cookie
elif cookie.startswith('laravel_session='):
laravel_session_cookie = cookie
cf_bm_cookie = cookies[-2]
output_str = cf_bm_cookie + '; ' + lang_cookie + '; ' + laravel_session_cookie

return output_str

`

Me sirve mucho, con esto podre ejecutar el repositorio que tiene @cleitonleonel, es cuestión de ver si esta completo y si funciona.
De todos modos ya estoy trabajando con el repositorio @cherrymaned hasta ahora llevo ya un 80% de avance
Dejo el repositorio original por si quiere apoyarse de este, si funciona te comento para que se haga la unión y sea mas rápido.

Aqui https://github.com/cherrymaned/QuotexAutomation

@cleitonleonel while sending ws message history/load, params sent are index, time, period, asset everything here are straight forward except index. Can you explain how index is calculated. Is there any correlation between index and time?? The use case is, i would like to get history of otc pairs for 6 months to train my ai model. I was trying for 2 days to decode the index, no success. share your suggestion.

@cleitonleonel while sending ws message history/load, params sent are index, time, period, asset everything here are straight forward except index. Can you explain how index is calculated. Is there any correlation between index and time?? The use case is, i would like to get history of otc pairs for 6 months to train my ai model. I was trying for 2 days to decode the index, no success. share your suggestion.

I used time as an index, it was what seemed most obvious to me, but it may not be correct, however it works

index = expiration.get_timestamp()

Não sei o porque de funcionar aqui sem nenhum erro kkk, mas consigo obter o ssid e cookies apenas com urllib3...

I don't know why it works here without any error lol, but I can get the ssid and cookies only with urllib3...

Captura de tela de 2023-04-11 11-12-02