Jump to content

HTTP request keeps failing


testrobot22

Recommended Posts

My custom made script doesn't start and the logger shows that some of my classes keep getting the message "Failed to load local script". I then pinpointed the exact problem to some async HTTP requests (both OkHttp and Unirest libraries). Synchronous requests work fine, but if I leave an async request in my code, the script will never be able to start and the logger will print that there is something wrong with the class that has the async method.

What can I do to fix this?

Link to comment
Share on other sites

46 minutes ago, Medusa said:

πŸ‘YouπŸ‘needπŸ‘toπŸ‘linkπŸ‘codeπŸ‘andπŸ‘errors

Error in logger : [ERROR][12/01 10:34:28 AM]: Failed to load local script : com/osbot/jagex/AccountManager.class

Β 

Code:

Β 

import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;

import java.util.concurrent.CompletableFuture;

public class AccountManager {

    public void registerAccount(String recaptchaResponse) {

       Unirest.post("http://www.google.com")
                .field("email", "xxxxx")
                .asJsonAsync(new Callback<JsonNode>() {
                    @Override
                    public void completed(HttpResponse<JsonNode> response) {
                        System.out.println("xxx");
                    }

                    @Override
                    public void failed(UnirestException e) {
                        e.printStackTrace();
                        cancelled();
                    }

                    @Override
                    public void cancelled() {
                        System.out.println("login failed.");
                    }
                });

    }
}

Β 

As I said, if I replace this with a synchronous call I don't get that error. The same goes for both OkHttp and Unirest libs.

Edited by testrobot22
Link to comment
Share on other sites

Ugh, apparently, for some reason, OSBOT can't load this specific interface 'Callback', which is used for async calls. Does anyone have any idea why?? I'm using plenty of libs and everything else is working fine.

Caused by: java.lang.NoClassDefFoundError: okhttp3/Callback
Β Β  Β at com.bot.osrs.gui.FXController.registerAccount(FXController.java:44)
Β Β  Β ... 57 more
Caused by: java.lang.ClassNotFoundException: okhttp3.Callback
Β Β  Β at java.net.URLClassLoader.findClass(Unknown Source)
Β Β  Β at java.lang.ClassLoader.loadClass(Unknown Source)
Β Β  Β at java.lang.ClassLoader.loadClass(Unknown Source)
Β Β  Β ... 58 more

Β 

EDIT: It seems it's actually a Kotlin file: Callback.kt, I presume Osbot doesn't support that?

Β 

Edited by testrobot22
dddddddddd
Link to comment
Share on other sites

Why must I suffer.. lmao

Caused by: java.security.AccessControlException: access denied ("java.net.NetPermission" "getProxySelector")
Β Β  Β at java.security.AccessControlContext.checkPermission(Unknown Source)
Β Β  Β at java.security.AccessController.checkPermission(Unknown Source)
Β Β  Β at java.lang.SecurityManager.checkPermission(Unknown Source)
Β Β  Β at org.osbot.Gb.checkPermission(mh:186)
Β Β  Β at java.net.ProxySelector.getDefault(Unknown Source)
Β Β  Β at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:167)
Β Β  Β at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:211)

Β 

Edited by testrobot22
ddddddd
Link to comment
Share on other sites

Is this for creating accounts on runescape? If so you could create this as a console app and create a bunch of accounts then dump them into a text file and have your script read from that text file. The file will have to be in the osbot data folder. I think thats the only location that scripts can read/write from.

Link to comment
Share on other sites

20 hours ago, BravoTaco said:

Is this for creating accounts on runescape? If so you could create this as a console app and create a bunch of accounts then dump them into a text file and have your script read from that text file. The file will have to be in the osbot data folder. I think thats the only location that scripts can read/write from.

Yes, it's for registering accounts. The idea was to have all in one solution, though, of course I can just make account registration a separate process. Then again, I imagine, that I would still need sometimes to use HTTP requests, for example, to check GE prices.

Link to comment
Share on other sites

7 hours ago, testrobot22 said:

Yes, it's for registering accounts. The idea was to have all in one solution, though, of course I can just make account registration a separate process. Then again, I imagine, that I would still need sometimes to use HTTP requests, for example, to check GE prices.

For checking GE prices you can do it with HttpUrlConnection class. I once used it to compare github version vs the current script version.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
Γ—
Γ—
  • Create New...