googleplay-api icon indicating copy to clipboard operation
googleplay-api copied to clipboard

Cannot download any app

Open cstayyab opened this issue 4 years ago • 4 comments

When given command to download APK (e.g. com.facebook.katana)

server.download("com.facebook.katana")

Following error from generated protobuf python file is shown:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Development\googleplay-api\gpapi\googleplay.py", line 607, in download
    self.log(packageName)
  File "D:\Development\googleplay-api\gpapi\googleplay.py", line 634, in log
    response = googleplay_pb2.ResponseWrapper.FromString(response.content)
  File "c:\users\cstayyab\appdata\roaming\python\python38\site-packages\google\protobuf\internal\python_message.py", line 801, in FromString
    message.MergeFromString(s)
  File "c:\users\cstayyab\appdata\roaming\python\python38\site-packages\google\protobuf\internal\python_message.py", line 1137, in MergeFromString
    raise message_mod.DecodeError('Unexpected end-group tag.')
google.protobuf.message.DecodeError: Unexpected end-group tag.

cstayyab avatar Aug 05 '20 11:08 cstayyab

For me anyways, this issue only affects free apps. Downloads of paid apps continue to work.

The culprit appears to be here:

https://github.com/NoMore201/googleplay-api/blob/664c399f8196e1eb7d2fcda4af34e5dc1fca0f20/gpapi/googleplay.py#L616

The commit history says:

This function is needed by the purchase API to insert app into user's
library. Without this, new apps won't be downloaded

This no longer appears to be the case. After removing this line, I ran four tests, all of which acted as expected:

  • Download a free app I've downloaded before: succeeds
  • Download a free app I've never downloaded before: succeeds
  • Download a paid app I've already paid for: succeeds
  • Download a paid app I haven't paid for: fails as expected with gpapi.googleplay.RequestError: 'App not purchased'

Inside the log() function, a request is made to the LOG_URL. Currently the response always has (for me anyways) an HTTP 400 status code, along with html content containing:

400. That's an error.

The server cannot process the request because it is malformed. It should not be retried. That's all we know.

An attempt is made to treat the html content as a protobuf, which generates that exception.

@cstayyab If you remove the line mentioned above, does it work for you?

I think it would be safe to just remove the log() function entirely... but I don't know if it might break things for others.

gurnec avatar Aug 10 '20 21:08 gurnec

Ha..! Nice find @gurnec, that does fix it for me too.

OJFord avatar Nov 29 '20 16:11 OJFord

@cstayyab If you remove the line mentioned above, does it work for you?

Yes, it works. Thanks. Can someone generate a PR for this?

cstayyab avatar Dec 08 '20 06:12 cstayyab

Gentle ping @NoMore201 - would be great to have this fixed without needing manual edits / installing forks. Cheers 🙂

OJFord avatar Jan 28 '21 13:01 OJFord