Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] #46

Open
MaxWvM opened this issue May 17, 2021 · 20 comments

Comments

@MaxWvM
Copy link

MaxWvM commented May 17, 2021

when trying to start the API today i was greeted by this line..
I tried updating the project files from 1.1.3 to 1.1.4, but allas this did not fix my problem.
might anyone know how to fix this?


full output in attatched file, but this is the 'caused by' list

error log.docx

Caused by: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:505) ~[json-20180813.jar!/:na]
at org.json.JSONObject.(JSONObject.java:215) ~[json-20180813.jar!/:na]
at org.json.JSONObject.(JSONObject.java:399) ~[json-20180813.jar!/:na]
at ok.work.etoroapi.client.UserContext.getAccountData(UserContext.kt:45) ~[classes!/:na]
at ok.work.etoroapi.client.UserContext.setupAuthorizationContext(UserContext.kt:36) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
... 39 common frames omitted

@aezequiel
Copy link

aezequiel commented May 29, 2021

Hello, good afternoon. I downloaded the application, and the same thing happened to me. I found out that etoro added a new header from an x-csrf-token call, which is currently not being sent. modify these 3 files and now it works correctly.

Another thing I had to change is the version of the chrome driver, for a more current one

Maybe I can help you.
Greetings

RequestUtils.kt
package ok.work.etoroapi.client

import ok.work.etoroapi.client.browser.EtoroMetadata
import ok.work.etoroapi.model.TradingMode
import okhttp3.Request
import java.net.URI
import java.net.http.HttpRequest
import kotlin.math.round
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

fun prepareRequest(path: String, auth: String, mode: TradingMode, credentials: EtoroMetadata): HttpRequest.Builder {

val now = LocalDateTime.now()
val formatter = DateTimeFormatter.ISO_DATE_TIME
val formatted = now.format(formatter)
val dt = formatted.split(".")[0]
println("prepareRequest Current Date and Time: $dt")

return HttpRequest.newBuilder().uri(URI("${credentials.baseUrl}/${path}"))
        .header("authority", credentials.domain)
        .header("accounttype", mode.name)
        .header("x-sts-appdomain", credentials.baseUrl)
        .header("content-type", "application/json;charset=UTF-8")
        .header("accept", "application/json, text/plain, */*")
        .header("x-sts-gatewayappid", "90631448-9A01-4860-9FA5-B4EBCDE5EA1D")
        .header("applicationidentifier", "ReToro")
        .header("applicationversion", "326.0.3")
        .header("origin", credentials.baseUrl)
        .header("sec-fetch-site", "same-origin")
        .header("sec-fetch-mode", "cors")
        .header("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
        .header("authorization", auth)
        .header("referer", "${credentials.baseUrl}/login")
        .header("cookie", credentials.cookies)
		
		.header("sec-fetch-dest", "empty")
		
		.header("x-csrf-token", "$credentials.cToken")
		.header("x-sts-clienttime", "$dt")

}

fun prepareOkRequest(path: String, auth: String, mode: TradingMode, credentials: EtoroMetadata): Request.Builder {

val now = LocalDateTime.now()
val formatter = DateTimeFormatter.ISO_DATE_TIME
val formatted = now.format(formatter)
val dt = formatted.split(".")[0]
println("prepareRequest Current Date and Time: $dt")

return Request.Builder().url("${credentials.baseUrl}/${path}")
        .header("authority", credentials.domain)
        .header("accounttype", mode.name)
        .header("x-sts-appdomain", credentials.baseUrl)
        .header("content-type", "application/json;charset=UTF-8")
        .header("accept", "application/json, text/plain, */*")
        .header("x-sts-gatewayappid", "90631448-9A01-4860-9FA5-B4EBCDE5EA1D")
        .header("applicationidentifier", "ReToro")
        .header("applicationversion", "326.0.3")
        .header("origin", credentials.baseUrl)
        .header("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
        .header("sec-fetch-site", "same-origin")
        .header("sec-fetch-mode", "cors")
        .header("authorization", auth)
        .header("referer", "${credentials.baseUrl}/login")
        .header("cookie", credentials.cookies)
		
		.header("sec-fetch-dest", "empty")
		
		.header("x-csrf-token", "$credentials.cToken")
		.header("x-sts-clienttime", "$dt")

}

fun Double.round(decimals: Int): Double {
var multiplier = 1.0
repeat(decimals) { multiplier *= 10 }
return round(this * multiplier) / multiplier
}

EtoroBrowserContext.kt
package ok.work.etoroapi.client.browser

import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import java.lang.RuntimeException
import java.util.*
import javax.annotation.PostConstruct

data class EtoroMetadata(val cookies: String, val token: String, val cToken: String, val lsPassword: String, val baseUrl: String, val domain: String)

@component
class EtoroMetadataService(@value("${etoro.baseUrl}") val baseUrl: String, @value("${etoro.domain}") val domain: String) {

private lateinit var cookies: String
private lateinit var token: String
private lateinit var cToken: String
private lateinit var expirationTime: Date
private lateinit var driver: ChromeDriver
private lateinit var opts: ChromeOptions

@PostConstruct
fun init() {

    val pathToDriver: String = when {
        System.getProperty("os.name").startsWith("Mac") -> {
            "drivers/mac/chromedriver"
        }
        System.getProperty("os.name").toLowerCase().contains("windows") -> {
            "drivers/windows/chromedriver.exe"
        }
        else -> {
            "drivers/ubuntu/chromedriver"
        }
    }

    opts = ChromeOptions()
    System.setProperty("webdriver.chrome.driver", pathToDriver)
    opts.addArguments("start-maximized")
    opts.addArguments("--disable-blink-features=AutomationControlled")
    login()
}

fun login() {
    driver = ChromeDriver(opts)

    driver.get("$baseUrl/login")
    val email = System.getenv("LOGIN")
    val password = System.getenv("PASSWORD")
    if (email == null || password == null) {
        throw RuntimeException("LOGIN and/or PASSWORD environment variables are missing")
    }
    driver.findElementById("username").sendKeys(email)
    driver.findElementById("password").sendKeys(password)
    driver.findElementByClassName("blue-btn").click()
    var seconds = 0
    while (true) {
        try {
            token = driver.executeScript("return JSON.parse(atob(window.localStorage.loginData)).stsData_app_1.accessToken;") as String
            println("Token retrieved after %d seconds".format(seconds))
            break
        } catch (e: Exception) {
            if (seconds > 5) {
                throw RuntimeException("Failed to retrieve token")
            }
            Thread.sleep(1000)
            seconds++
        }
        cToken = driver.executeScript("return window.localStorage.cToken") as String

    }
    expirationTime = Date(driver.executeScript("return JSON.parse(atob(window.localStorage.loginData)).stsData_app_1.expirationUnixTimeMs;") as Long)
    println(token)
    println("expires at: $expirationTime")
    val cookiesSet = driver.manage().cookies
    cookies = cookiesSet.toList().joinToString("; ") { cookie -> "${cookie.name}=${cookie.value}" }
    println("cookies: $cookies")
	println("cToken: $cToken")

    driver.quit()
}

fun getMetadata(): EtoroMetadata {
    if (Date().after(expirationTime)) {
        login()
    }
    return EtoroMetadata(
            cookies,
            token,
			cToken,
            """{"UserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36","ApplicationVersion":"213.0.2","ApplicationName":"ReToro","AccountType":"Demo","ApplicationIdentifier":"ReToro"}""",
            baseUrl,
            domain
    )
}

}

@ok24601
Copy link
Owner

ok24601 commented May 30, 2021

hi, appreciate your help but, it didn't work for me

@claudio0603
Copy link

I´ve debugged this error and found that this request:
https://www.etoro.com/sapi/trade-real/instruments/private/index?client_request_id=SOME_RANDOM_CLIENT_ID

returns: "error code: 1020 which causes"

After a quick google search I found out that this is from cloudflare:
What is a 1020 Error on Cloudflare? Cloudflare Error 1020: Access Denied indicates that you've violated a firewall rule and your connection request has been blocked.

Does someone have any ideas how to bypass this?

@WelschChristopher
Copy link

Hey, check this one here:
#44

I assume:
The user-agend is used to generate the tokens and If you use differend user-agend header in the inital login request, compared to the user-agend used in the kotlin code, cloudflare blocks your requests.

So always try to keep the user-agend and in kotlin equal to your installed chrome. We currently have issues again. I will update sync all values again and will post the update.

@WelschChristopher
Copy link

Hey, small update...so we sync the agent used in the kotlin code with our browser one and it works fine again. So 100% related to the user-agent.
So always keep it in sync OR disable auto update in your chrome browser.

@claudio0603
Copy link

Hey @loki919, thanks for your reply, it worked.

@andreiciceu
Copy link

Hey, small update...so we sync the agent used in the kotlin code with our browser one and it works fine again. So 100% related to the user-agent.
So always keep it in sync OR disable auto update in your chrome browser.

Hey, nice work, but how would you approach this when running inside Docker?

@mzeeshanilyas
Copy link

mzeeshanilyas commented Jun 27, 2021

Hey guys, i was using the same build i modify the user agent which is 91 as i have chrome 91 and driver is also 91.
Can anyone tell me why this is not working ? please see the attached error:
JAVA 11 SDK
Chrome V91

2021-06-27 02:35:53.581 WARN 2228 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'browserHttpClient': Unsatisfied dependency expressed through field 'userContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userContext': Invocation of init method failed; nested exception is kotlin.UninitializedPropertyAccessException: lateinit property userContext has not been initialized
2021-06-27 02:35:53.605 INFO 2228 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-06-27 02:35:53.665 INFO 2228 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-27 02:35:53.683 ERROR 2228 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'browserHttpClient': Unsatisfied dependency expressed through field 'userContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userContext': Invocation of init method failed; nested exception is kotlin.UninitializedPropertyAccessException: lateinit property userContext has not been initialized
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at ok.work.etoroapi.EtoroApiApplicationKt.main(EtoroApiApplication.kt:54) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[etoro-api-0.1.4.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[etoro-api-0.1.4.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) ~[etoro-api-0.1.4.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) ~[etoro-api-0.1.4.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userContext': Invocation of init method failed; nested exception is kotlin.UninitializedPropertyAccessException: lateinit property userContext has not been initialized
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
... 27 common frames omitted
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property userContext has not been initialized
at ok.work.etoroapi.client.browser.BrowserHttpClient.getUserContext(BrowserHttpClient.kt:15) ~[classes!/:na]
at ok.work.etoroapi.client.browser.BrowserHttpClient.fetchAccountData(BrowserHttpClient.kt:21) ~[classes!/:na]
at ok.work.etoroapi.client.UserContext.setupAuthorizationContext(UserContext.kt:40) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
... 39 common frames omitted

@mzeeshanilyas
Copy link

@loki919 @ok24601 @claudio0603 is this build is working with v91 ?
I need your help.

@WarlaxZ
Copy link

WarlaxZ commented Jun 30, 2021

yeah any official updates on this or does anyone have a fork I can clone? :)

@mzeeshanilyas
Copy link

I tried alot but this built is not working anymore for Chrome V91, Even not for older version. And no one help here :(
Anyway iam trying by myself to fixed it, but it would take too much time, as iam new learner of this programming language.

@mzeeshanilyas
Copy link

by using swagger most of the calls are not working, Error Code : 1020 occur, even i put the user-agent too but still not working.
Is there anyone who will check and let us know is it working with Chrome V91?

@WelschChristopher
Copy link

WelschChristopher commented Jun 30, 2021

We are currently working wih chromeV91. It works totaly fine.
There seem to be some problems if you are logged in with any other browser on the same machine.
My mate used firefox to login and chrome + chrome driver for the api. this also seem to be nasty. I assume cloudflare uses some machine id and the user-agent for the token. Having 2 session with different browsers makes it complicated.

@mzeeshanilyas
Copy link

@loki919 If you don't mind will you please share the new build which works with V91. I tried it but it not works. I also changes the user agent in code from , but nothing happened. Here are the some changes i made it but it not works.

1st Changed :
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"91\", \"Google Chrome\";v=\"91\"",\n" +

2nd Changed :
"""{"user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36","ApplicationVersion":"326.0.3","ApplicationName":"ReToro","AccountType":"Demo","ApplicationIdentifier":"ReToro"}""",

@ok24601
Copy link
Owner

ok24601 commented Jul 3, 2021

Hi guys,
Sorry for not responding so long. The error you got is because of Cloud flare protection. The only way to fix it for good is to make all REST calls using selenium drevier.executeScript. Example is here: https://github.com/ok24601/etoro-api/blob/master/src/main/kotlin/ok/work/etoroapi/client/browser/BrowserHttpClient.kt

@WarlaxZ
Copy link

WarlaxZ commented Jul 3, 2021 via email

@ok24601
Copy link
Owner

ok24601 commented Jul 3, 2021

i'm using all cookies after login already

@mzeeshanilyas
Copy link

Hi guys,
Sorry for not responding so long. The error you got is because of Cloud flare protection. The only way to fix it for good is to make all REST calls using selenium drevier.executeScript. Example is here: https://github.com/ok24601/etoro-api/blob/master/src/main/kotlin/ok/work/etoroapi/client/browser/BrowserHttpClient.kt

Yes iam already did it with this. Thanks for the reply.. I already set lot of calls in working condition. Only Update Position is remaining. But sometime it gives an error due to injecting execute script in browser. Anyways but its working by using Selenium Execute Function.

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

@mzeeshanilyas
Copy link

@WarlaxZ is it working for you same build without using selenium drevier.executeScript ? by using normal api calls with authorization token ? By the way it works only first 2 calls and than iam unable to do it. I don't know what happened. I tried alot but i found 1020 error. no matter what iam login with some other browser or not. But it gives an errror for most of the calls 1020 like getCash, getAssetInfo

@AndreJackBia
Copy link

@ok24601 so you are planning to rewrite the API calls using executeScript?
@mzeeshanilyas do you mind to share your work in pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants