PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

version 0.4.1 doesn't works as well as before

Open AbandonedCart opened this issue 10 years ago • 21 comments

From @tommywuhaojie:

After this new login, version 0.4.1 doesn't works as well as before. It throws exception almost every time when I login using both google key and PTC, So I have to roll back my App to use 0.4.0 API.

AbandonedCart avatar Aug 30 '16 20:08 AbandonedCart

@tommywuhaojie and other having this problem please post a stackTrace

PokeAlert avatar Aug 30 '16 20:08 PokeAlert

Same here !

I use TransferOnePidgeyExample with GoogleAutoCredentialProvider implementation. I have this exception one in three time :

D/RequestHandler: Authenticated with static token
Exception in thread "main" com.pokegoapi.exceptions.AsyncPokemonGoException: Unknown exception occurred. 
    at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:46)
    at com.pokegoapi.main.RequestHandler.sendServerRequests(RequestHandler.java:156)
    at com.pokegoapi.api.PokemonGo.fireRequestBlock(PokemonGo.java:211)
    at com.pokegoapi.api.PokemonGo.initialize(PokemonGo.java:168)
    at com.pokegoapi.api.PokemonGo.login(PokemonGo.java:164)
    at com.pokegoapi.examples.TransferOnePidgeyExample.main(TransferOnePidgeyExample.java:53)
Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null
    at rx.exceptions.Exceptions.propagate(Exceptions.java:58)
    at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:465)
    at rx.observables.BlockingObservable.first(BlockingObservable.java:168)
    at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:38)
    ... 5 more
Caused by: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null
    at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:110)
    at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:87)
    at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:74)
    at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:43)
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    at rx.Observable.subscribe(Observable.java:9957)
    at rx.Observable.subscribe(Observable.java:9924)
    at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:445)
    ... 7 more
Caused by: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null
    at com.pokegoapi.main.ServerRequest.getData(ServerRequest.java:80)
    at com.pokegoapi.main.RequestHandler.run(RequestHandler.java:313)
    at java.lang.Thread.run(Thread.java:745)

gdespres avatar Aug 31 '16 13:08 gdespres

That is just a null response from server.

FabianTerhorst avatar Aug 31 '16 14:08 FabianTerhorst

maybe due to overloaded google servers ? It's not everytime.

gdespres avatar Aug 31 '16 14:08 gdespres

This exception is after the login.

FabianTerhorst avatar Aug 31 '16 14:08 FabianTerhorst

I will post stackTrace later

tommywuhaojie avatar Aug 31 '16 18:08 tommywuhaojie

@PokeAlert @LoungeKatt @FabianTerhorst StackTrace attached

Google Authentication Key Login:

I/System.out: D/RequestHandler: Authenticated with static token W/System.err: com.pokegoapi.exceptions.AsyncPokemonGoException: Unknown exception occurred. W/System.err: at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:46) W/System.err: at com.pokegoapi.main.RequestHandler.sendServerRequests(RequestHandler.java:155) W/System.err: at com.pokegoapi.api.PokemonGo.fireRequestBlockOne(PokemonGo.java:210) W/System.err: at com.pokegoapi.api.PokemonGo.initialize(PokemonGo.java:168) W/System.err: at com.pokegoapi.api.PokemonGo.login(PokemonGo.java:164) W/System.err: at com.xxxx.LoginActivity$5.run(LoginActivity.java:224) W/System.err: at java.lang.Thread.run(Thread.java:818) W/System.err: Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at rx.exceptions.Exceptions.propagate(Exceptions.java:58) W/System.err: at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:465) W/System.err: at rx.observables.BlockingObservable.first(BlockingObservable.java:168) W/System.err: at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:38) W/System.err: ... 6 more W/System.err: Caused by: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:109) W/System.err: at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:86) W/System.err: at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:74) W/System.err: at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:43) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.Observable.subscribe(Observable.java:9957) W/System.err: at rx.Observable.subscribe(Observable.java:9924) W/System.err: at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:445) W/System.err: ... 8 more W/System.err: Caused by: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at com.pokegoapi.main.ServerRequest.getData(ServerRequest.java:80) W/System.err: at com.pokegoapi.main.RequestHandler.run(RequestHandler.java:296) W/System.err: ... 1 more V/RenderScript: Application requested CPU execution

PTC Login:

W/System.err: com.pokegoapi.exceptions.AsyncPokemonGoException: Unknown exception occurred. W/System.err: at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:46) W/System.err: at com.pokegoapi.main.RequestHandler.sendServerRequests(RequestHandler.java:155) W/System.err: at com.pokegoapi.api.PokemonGo.fireRequestBlockOne(PokemonGo.java:210) W/System.err: at com.pokegoapi.api.PokemonGo.initialize(PokemonGo.java:168) W/System.err: at com.pokegoapi.api.PokemonGo.login(PokemonGo.java:164) W/System.err: at com.xxxxx.LoginActivity$5.run(LoginActivity.java:254) W/System.err: at java.lang.Thread.run(Thread.java:818) W/System.err: Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at rx.exceptions.Exceptions.propagate(Exceptions.java:58) W/System.err: at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:465) W/System.err: at rx.observables.BlockingObservable.first(BlockingObservable.java:168) W/System.err: at com.pokegoapi.util.AsyncHelper.toBlocking(AsyncHelper.java:38) W/System.err: ... 6 more W/System.err: Caused by: java.util.concurrent.ExecutionException: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:109) W/System.err: at com.pokegoapi.main.RequestHandler$1.get(RequestHandler.java:86) W/System.err: at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:74) W/System.err: at rx.internal.operators.OnSubscribeToObservableFuture$ToObservableFuture.call(OnSubscribeToObservableFuture.java:43) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.Observable.subscribe(Observable.java:9957) W/System.err: at rx.Observable.subscribe(Observable.java:9924) W/System.err: at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:445) W/System.err: ... 8 more W/System.err: Caused by: com.google.protobuf.InvalidProtocolBufferException: Contents of buffer are null W/System.err: at com.pokegoapi.main.ServerRequest.getData(ServerRequest.java:80) W/System.err: at com.pokegoapi.main.RequestHandler.run(RequestHandler.java:296) W/System.err: ... 1 more

tommywuhaojie avatar Sep 02 '16 06:09 tommywuhaojie

That's only a null response from server

FabianTerhorst avatar Sep 02 '16 06:09 FabianTerhorst

@FabianTerhorst I don't get exception if I use 0.4.0 API though

tommywuhaojie avatar Sep 02 '16 06:09 tommywuhaojie

My Google login source code:

` Thread networkThread = new Thread(new Runnable() {

        public void run() {
            OkHttpClient httpClient = new OkHttpClient();

            /**
             * Google:
             * You will need to redirect your user to GoogleUserCredentialProvider.LOGIN_URL
             * Afer this, the user must signin on google and get the token that will be show to him.
             * This token will need to be put as argument to login.
             */
            GoogleUserCredentialProvider provider = null;
            try {

                provider = new GoogleUserCredentialProvider(httpClient);

                if(google.isChecked()){
                    // google login
                    // we should be able to login with this token
                    String key = ((EditText) findViewById(R.id.google_key)).getText().toString().trim();
                    provider.login(key);

                    Log.d("DEBUG", "refresh token: " + provider.getRefreshToken());

                    Global.go = new PokemonGo(httpClient);
                    Global.go.login(provider); // login
                    ...`

tommywuhaojie avatar Sep 02 '16 06:09 tommywuhaojie

The current Development branch is kinda screwy with Credential provider / PokemonGO construction. The initial login when you instantiate the PTCCredentialProvider always works, but then the PokemonGo.login() method is pretty much a crapshoot. Even when I introduce a 10 sec delay between those two things it will often hang, or throw an exception, or ... both (or, it just works and life is good). I've spent the last hour trying to debug it but it's hard because it seems to be a timing issue; when I introduce breakpoints and step through ... it doesn't act badly.

broach avatar Sep 02 '16 22:09 broach

I got same problem :(. How to fix it ?

hanhmh1203 avatar Sep 04 '16 08:09 hanhmh1203

You can use this dirty code pending a fix :

PokemonGo go = ...
boolean logged = false;
int attempt = 1;
do {
    try {
        go.login(provider);
        logged = true;
    } catch(Exception e) {
        attempt++;
        if (attempt > 3) {
            throw e;
        }
    }
} while(!logged)

gdespres avatar Sep 04 '16 08:09 gdespres

The problem is ProkemonGo.login() can end up firing multiple requests too fast and hitting the server rate limit.

Basically, there's a pretty good chance the GET_PLAYER and CHECK_CHALLENGE requests will get processed by the run() loop in RequestHandler and then the requests created by initialize() (DOWNLOAD_REMOTE_CONFIG_VERSION, CHECK_CHALLENGE, GET_HATCHED_EGGS, GET_INVENTORY, CHECK_AWARDED_BADGES, DOWNLOAD_SETTINGS) get sent separately < 1 second later when the run() loop iterates again (it only has a 350ms delay). You end up getting back empty responses for all of them and then the API throws an unchecked 'AsyncPokemonGoException`.

Adding a 5s delay in .login() before calling initialize() solves the issue but that's ugly. I'm thinking that the run() loop should simply have a minimum time to send in it to keep from doing this.

Does anyone know the what the rate limiting time is these days? I only send map requests once per 10s, but I don't know what the game client is doing these days without setting up a MITM and checking it.

As a side note - this also causes a memory leak. The exception gets thrown in the loop in sendServerRequests(ServerRequest... serverRequests) on the first call to .get() on the first Obsevable. Because of this the other results are never removed from the resultMap (The removing of the response from the map happens inside get() in the Futures themselves, and none of the other futures are handled).

broach avatar Sep 04 '16 16:09 broach

Get GET_MAP_OBJECTS has a rate limit of at least 10 seconds (you can see that in the settings if you do a DOWNLOAD_SETTINGS call). All other calls do not really have a rate limit from what I can see. The game client does the initial 5 login calls all within about two seconds (can be seen here: http://i.imgur.com/zVM1f7g.png)

Also noticed that the time between GET_MAP_OBJECTS can very between 10 and 30 seconds. Unsure why this happens. Maybe the app can tell if you are moving or not... still unsure

mjmjelde avatar Sep 04 '16 16:09 mjmjelde

"All other calls do not really have a rate limit from what I can see" ... except they do, demonstrated here :)

I suspect the reason the calls in the png you posted are being made multiple times is that the game client is getting back the empty responses just like initialize() in the API currently does and then is re-trying.

broach avatar Sep 04 '16 17:09 broach

None of the calls in the png are being made multiple times. The first one is called twice only because its the one getting the rpc endpoint and once it gets that it has to make a new call. All the other requests are unique and get valid responses. These requests are the login requests that every client sends to get all the information it needs to play the game.

I'm more curious to see if multiple requests are being sent at the exact same time resulting in an invalid auth ticket to be send along with one of the request (or something similarly along these lines).

mjmjelde avatar Sep 04 '16 17:09 mjmjelde

Multiples can't be sent at the exact same time by design; they're dropped into the RequestHandler's workQueue and then picked up on each iteration of the run loop. That said, 350ms isn't much of a delay. I added the "min time between requests" to the run loop in my local clone and that indeed does prevent the problem from occurring. I set it to 5s which is fine for my purposes, but I should probably see if there's a threshold closer to 1s

broach avatar Sep 04 '16 17:09 broach

Yeah just a 1s minimum delay between the requests does the trick. Unmodified it will always fail for me if the requests get split over two iterations of the run loop.

broach avatar Sep 04 '16 18:09 broach

A bit of debugging this error and I have the read error. Most of the time when you get a null buffer error, you do get a response but the responses are null. This means you do get a response envelope that has the error code in it. When I call the login method and get the "Contents of buffer are null", the error in the envelope is "invalidPlatformRequest". This means the signature was generated wrong with the request somehow.

mjmjelde avatar Sep 04 '16 19:09 mjmjelde