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

Unable to authorize, possibly because of using a pre-Amazon Audible account #113

Open
Gilvern opened this issue Aug 16, 2022 · 20 comments
Open

Comments

@Gilvern
Copy link

Gilvern commented Aug 16, 2022

Error Report.md

@mkb79
Copy link
Owner

mkb79 commented Aug 16, 2022

It seams there is something wrong login with Audible username. Can you re-run quickstart and use login with a external browser? This way your browser will show you errors, if they occur.

@Gilvern
Copy link
Author

Gilvern commented Aug 16, 2022

I got very similar results using the Browser. Here is the output:

Error Report 2.md

I also have a pdf of the webpage exhibited by the Browser, but the main content is already in the error report.

@mkb79
Copy link
Owner

mkb79 commented Aug 16, 2022

Your login and device registration was successfully. But the registration response does not contain website_cookies. Maybe Audible does not give them for now for pre-Amazon accounts. Do you have knowledge with Python?

@Gilvern
Copy link
Author

Gilvern commented Aug 16, 2022

The honest answer is that I have very little experience with Python. (I do have some programming experience, but mainly with a couple of other higher-level systems. E.g. MatLab.) What is it that you would like me to do?

@mkb79
Copy link
Owner

mkb79 commented Aug 16, 2022

If you don’t use the standalone binary from release page you can change these line from

for cookie in tokens["website_cookies"]:

to

for cookie in tokens.get("website_cookies", {}):

After that reinstall the fixed audible package. This should let you use the quickstart command with external browser.

@Gilvern
Copy link
Author

Gilvern commented Aug 16, 2022

I am not using the standalone binary. So I will definitely give that a try! Thanks! (It may take me a little while!)

@mkb79
Copy link
Owner

mkb79 commented Aug 16, 2022

If you need any help you can contact me!

@Gilvern
Copy link
Author

Gilvern commented Aug 17, 2022

Here is what I did. I edited the register.py file in C:\Python38\Lib\site-packages\audible and deleted the register.cpython-38.pyc file in C:\Python38\Lib\site-packages\audible\__pycache__. I then ran audible-quickstart. The error has now changed. See below. I realize that this could be because I tried to hack the edit, which is why I have told you what I did, but honestly I do not think that is really the cause. (Python just constructed a new register.cpython-38.pyc file.)

Uncaught Exception
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\audible_cli\cli.py", line 46, in quickstart
    sys.exit(ctx.forward(cmd_quickstart.cli))
  File "c:\python38\lib\site-packages\click\core.py", line 781, in forward
    return __self.invoke(__cmd, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\click\decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\audible_cli\cmds\cmd_quickstart.py", line160, in cli
    build_auth_file(
  File "c:\python38\lib\site-packages\audible_cli\utils.py", line 88, in build_auth_file
    auth = Authenticator.from_login_external(
  File "c:\python38\lib\site-packages\audible\auth.py", line 497, in from_login_external
    auth._update_attrs(
  File "c:\python38\lib\site-packages\audible\auth.py", line 273, in _update_attrs
    setattr(self, attr, value)
  File "c:\python38\lib\site-packages\audible\auth.py", line 257, in __setattr__
    value = test_convert(attr, value)
  File "c:\python38\lib\site-packages\audible\utils.py", line 142, in test_convert
    return string_function_map[key](value) or value
  File "c:\python38\lib\site-packages\audible\utils.py", line 21, in _check_website_cookies
    raise TypeError(
TypeError: website_cookies: Value(s) of website_cookies have wrong type.

@mkb79
Copy link
Owner

mkb79 commented Aug 17, 2022

Okay. Then delete these two lines please:

for cookie in tokens["website_cookies"]:
        website_cookies[cookie["Name"]] = cookie["Value"].replace(r'"', r'')

This should resolve your issue.

@Gilvern
Copy link
Author

Gilvern commented Aug 17, 2022

We are still getting problems. (Maybe I should ask: is there some kind of limit to the number of registrations that one can make?)

Uncaught Exception
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\audible_cli\cli.py", line 46, in quickstart
    sys.exit(ctx.forward(cmd_quickstart.cli))
  File "c:\python38\lib\site-packages\click\core.py", line 781, in forward
    return __self.invoke(__cmd, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\click\decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\audible_cli\cmds\cmd_quickstart.py", line 160, in cli
    build_auth_file(
  File "c:\python38\lib\site-packages\audible_cli\utils.py", line 88, in build_auth_file
    auth = Authenticator.from_login_external(
  File "c:\python38\lib\site-packages\audible\auth.py", line 482, in from_login_external
    login_device = external_login(
  File "c:\python38\lib\site-packages\audible\login.py", line 573, in external_login
    authorization_code = parsed_url["openid.oa2.authorization_code"][0]
KeyError: 'openid.oa2.authorization_code'

@mkb79
Copy link
Owner

mkb79 commented Aug 17, 2022

Theoretical it is possible to register an unlimited number of devices. But your last error says, that your login was not successfully and the url you past in does not contain the authorization code. Can you try it again?

@Gilvern
Copy link
Author

Gilvern commented Aug 17, 2022

That was indeed my error: I pasted the wrong url. Here is the correct result:

Please insert the copied url (after login):
https://www.audible.co.uk/ap/maplanding?captcha_verified=1&openid.assoc_handle=amzn_audible_ios_lap_uk&openid.claimed_i
=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fid%2Famzn1.account.AHCNVF6QZ5A5KAJGKFDOG23YBL4Q&openid.identity=https%3A%2F%2Fw
w.audible.co.uk%2Fap%2Fid%2Famzn1.account.AHCNVF6QZ5A5KAJGKFDOG23YBL4Q&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.
penid.net%2Fauth%2F2.0&openid.op_endpoint=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fsignin&openid.response_nonce=2022-08-1
T10%3A10%3A36Z1855673379613494117&openid.return_to=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fmaplanding&openid.signed=asso
_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Cns.pape%2Cpape.auth_policies%2
pape.auth_time%2Coa2.authorization_code%2Ccaptcha_verified%2Csigned&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fexte
sions%2Fpape%2F1.0&openid.pape.auth_policies=http%3A%2F%2Fschemas.openid.net%2Fpape%2Fpolicies%2F2007%2F06%2Fnone&openi
.pape.auth_time=2022-08-17T10%3A10%3A36Z&openid.sig=3jIYStU7ijVJfSVqXJK9Qya6gJr3qHFsu3IXnd8qUq4%3D&serial=&openid.oa2.a
thorization_code=RHThiuvrZzFhnruvHbKBjmNN&openid.ns.oa2=http%3A%2F%2Fwww.amazon.com%2Fap%2Fext%2Foauth%2F2
Uncaught Exception
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\audible_cli\cli.py", line 46, in quickstart
    sys.exit(ctx.forward(cmd_quickstart.cli))
  File "c:\python38\lib\site-packages\click\core.py", line 781, in forward
    return __self.invoke(__cmd, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\click\decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\python38\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\python38\lib\site-packages\audible_cli\cmds\cmd_quickstart.py", line 160, in cli
    build_auth_file(
  File "c:\python38\lib\site-packages\audible_cli\utils.py", line 88, in build_auth_file
    auth = Authenticator.from_login_external(
  File "c:\python38\lib\site-packages\audible\auth.py", line 497, in from_login_external
    auth._update_attrs(
  File "c:\python38\lib\site-packages\audible\auth.py", line 273, in _update_attrs
    setattr(self, attr, value)
  File "c:\python38\lib\site-packages\audible\auth.py", line 257, in __setattr__
    value = test_convert(attr, value)
  File "c:\python38\lib\site-packages\audible\utils.py", line 142, in test_convert
    return string_function_map[key](value) or value
  File "c:\python38\lib\site-packages\audible\utils.py", line 21, in _check_website_cookies
    raise TypeError(
TypeError: website_cookies: Value(s) of website_cookies have wrong type.

@mkb79
Copy link
Owner

mkb79 commented Aug 17, 2022

Okay, I know what happens.

Please change

website_cookies = dict()
    for cookie in tokens["website_cookies"]:
        website_cookies[cookie["Name"]] = cookie["Value"].replace(r'"', r'')

to

website_cookies = None

This should definitely solve this issue and set website cookies to None. They are not needed by audible-cli yet and can be requested later again.

@Gilvern
Copy link
Author

Gilvern commented Aug 17, 2022

It works! Thanks! (See below for confirmation and a little more information.)

I now have a follow-up question: if I am being told that "Successfully registered FirstName's 6th Audible for iPhone.", then what happened to the other 5 Audible's for iPhone? (The first probably genuinely corresponds to an iPhone. But we have here the 6th.) It would be nice to tidy up the other 4!

Thanks again! (And I learned a little bit about Python along the way.)

Please insert the copied url (after login):
https://www.audible.co.uk/ap/maplanding?captcha_verified=1&openid.assoc_handle=amzn_audible_ios_lap_uk&openid.claimed_id=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fid%2Famzn1.account.AHCNVF6QZ5A5KAJGKFDOG23YBL4Q&openid.identity=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fid%2Famzn1.account.AHCNVF6QZ5A5KAJGKFDOG23YBL4Q&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.op_endpoint=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fsignin&openid.response_nonce=2022-08-17T12%3A39%3A23Z-1566482569615371081&openid.return_to=https%3A%2F%2Fwww.audible.co.uk%2Fap%2Fmaplanding&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Cns.pape%2Cpape.auth_policies%2Cpape.auth_time%2Coa2.authorization_code%2Ccaptcha_verified%2Csigned&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.auth_policies=http%3A%2F%2Fschemas.openid.net%2Fpape%2Fpolicies%2F2007%2F06%2Fnone&openid.pape.auth_time=2022-08-17T12%3A39%3A23Z&openid.sig=nMuqUvDGAAgic00pzH0PCkTTtgU%2FJGmyGyvQbd7SA60%3D&serial=&openid.oa2.authorization_code=RHXnBuKPrvlQlVRpAwjCsSPn&openid.ns.oa2=http%3A%2F%2Fwww.amazon.com%2Fap%2Fext%2Foauth%2F2

Successfully registered FirstName's 6th Audible for iPhone.
Profile initials added to config
Config written to config.toml```

@mkb79
Copy link
Owner

mkb79 commented Aug 17, 2022

That sounds great. You can view and remove devices on the Amazon website under settings>devices or so. I think this should be the same for pre-Amazon accounts. If not, you can take a look on the Audible website under settings if there is a devices section.

If not, you can deregister all devices by making a special API request.

@Gilvern
Copy link
Author

Gilvern commented Aug 17, 2022

I checked the Audible website, and it says that you would need to contact Customer Services if you still log in with a username. In my experience the people at Customer Services are always delightful, but I am not sure that I want to explain to them how I have ended up with 6 devices registered. So it would be quite helpful to know about that API request! It would also be helpful to know: are some of these devices "virtual" devices created while debugging the code? (I probably would not use the API request immediately: I am still learning about your system, and at least my iPhone and Windows 7 computer are both working now..)

@mkb79
Copy link
Owner

mkb79 commented Aug 17, 2022

Sorry for the delay. But I'm on annual vacation right now! The virtual devices cannot be distinguished from the real devices. At least not if you use my package.

To deregister all devices for your account, create a file named cmd_deregister-all.py in your plugin dir and insert the code below:

import click
from audible import Authenticator

from audible_cli.cmds import cmd_manage as manage


CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])

@click.command("deregister-all", context_settings=CONTEXT_SETTINGS)
@click.option(
    "--auth-file", "-f",
    type=click.Path(exists=False, file_okay=True),
    callback=manage.check_if_auth_file_exists,
    prompt="Please enter name for the auth file",
    help="The auth file name (without dir)."
)
@click.option(
    "--password", "-p",
    help="The optional password for the auth file."
)
def cli(auth_file, password):
    """Deregister all devices for the given auth file account"""
    auth = Authenticator.from_file(auth_file, password)
    auth.refresh_access_token()
    auth.deregister_device(deregister_all=True)
    click.echo(f"all devices for given auth file account deregistered")

Then you can run audible deregister-all -f AUTH_FILE_NAME_WITHOUT_PATH and it should deregister all devices. After running this command successfully you can try to open the Audible App on your iOS device. It should say that you need to re-authenticated. If this works you can delete the config.toml and the auth file from the Audible config dir and re-run quickstart.

@Gilvern
Copy link
Author

Gilvern commented Aug 18, 2022

You really should not be doing this while on vacation! Thanks again!

I have run the deactivation code, and the results are intriguing! (I removed the 'f' from 'click.echo(f"all devices for given auth file account deregistered")' first.)

  1. I clearly did succeed in deregistering my Windows 7 computer. (I could no longer export my library or download a book using audible-cli.)
  2. My iPhone does not appear to have been deregistered.
  3. When I reregistered, I was told that "Successfully registered FirstName's 6th Audible for iPhone". That is the same number as before, suggesting that exactly one "device" was deregistered.

Possible explanations for these data:

  • I believe that Audible only allows one to register a small number of phones/tablets (3?) for use with their app. So those devices may be on some other system. Or at least audible-cli may not be able to deregister them.
  • It is just possible that the number 6 is a coincidence. Maybe I have 5 other devices registered in some way via something like this system. (I.e. the earlier attempts to register using audible-quickstart did not result in "lost" registrations.) But, if so, then those devices do not seem to have been deregistered either. E.g.: (1) we are still getting "6th Audible for iPhone"; and (2) iTunes still plays aax files on my Windows 7 computer. Fully testing this question would require quite an extensive investigation. For example, iTunes may only need the activation-bytes to work.
  • Or perhaps audible-cli only actually succeeds in deregistering those devices "closely associated with" the auth file used?

@mkb79
Copy link
Owner

mkb79 commented Aug 18, 2022

When it comes to numbering, he actually always takes the next free number. If deregistering a device, it free up this number.

Have you read this?

Sorry if I don’t answer all your questions yet. Will do it later.

@Gilvern
Copy link
Author

Gilvern commented Aug 21, 2022

With apologies for the long pause: I have been exploring the capabilities of your system. Wow! It is magnificent! Thanks for contributing this!

I think I can also now give a much more focused explanation of what I found vis-a-vis registration:

  1. As you pointed out right at the start, the attempted registrations via web browser were all successful. But the crucial authentication information for the devices created was lost when audible-cli crashed because of the website_cookies issue.

  2. Your plugin cmd_deregister-all.py works, but not as anticipated. It only deletes the device associated with the auth_file, not all devices (notwithstanding the line auth.deregister_device(deregister_all=True)). [My iPhone did not get deregistered, nor did the zombie devices. But the device associated with the auth_file did.] Maybe there has been a change in the api at Audible's end?

  3. I had seen the Audible help page you mention, explaining about how to handle devices: [Audible Help](https://help.audible.com/s/article/how-can-i-deactivate-devices-that-are-using-the-audible-app?language=en_US). But I would have much rather deregistered devices using audible-cli, even if that meant reregistering the ones I actually wanted.

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

2 participants