Git Product home page Git Product logo

Comments (5)

mkb79 avatar mkb79 commented on May 24, 2024

Thank you for opening this issue.

If you run

auth = audible.Authenticator.from_file("credentials.json")
def get_bookmarks(url, **kwargs):
    with audible.Client(auth=auth, response_callback=lambda x: x) as client:
        library = client.get(
            url,
            **kwargs
        )
        return library

you get the raw (unprepared) httpx response. But this didn’t solve your issue.

You've forgotten to provide the type and asin in your url params. So the get_bookmarks function must look like:

def get_bookmarks(url, asin, **kwargs):
    with audible.Client(auth=auth) as client:
        params = {
            "type": "AUDI",
            "key": asin
        }
        library = client.get(
            url,
            params=params,
            **kwargs
        )
        return library

Known allowed types are AUDI or EBOK!

from audible.

GGyll avatar GGyll commented on May 24, 2024

Thanks for the fast response.
I actually had those query parameters but had hardcoded them into the URL like so
f"https://cde-ta-g7g.amazon.com/FionaCDEServiceEngine/sidecar?type=AUDI&key={ASIN}"

ASIN = "1473565421"

Still with your solution I get None object, having a custom_callback gives me the dictionary I want, but you said this isn't a solution?

My code:
def get_bookmarks(url, asin, **kwargs):
    with audible.Client(auth=auth) as client:
        params = {
            "type": "AUDI",
            "key": asin
        }
        library = client.get(
            url,
            params=params,
            **kwargs
        )
        return library
bookmarks_url = "https://cde-ta-g7g.amazon.com/FionaCDEServiceEngine/sidecar"
bookmarks_dict = get_bookmarks(bookmarks_url, ASIN)

returns library = None

from audible.

mkb79 avatar mkb79 commented on May 24, 2024

Still with your solution I get None object, having a custom_callback gives me the dictionary I want, but you said this isn't a solution?

I thought you provide the url without the params. If I understood you correctly, you've got None with the default callback, and the dict with your custom callback for the same asin?

The default callback is the following:

def default_response_callback(resp: httpx.Response) -> Union[Dict, str]:
    raise_for_status(resp)
    return convert_response_content(resp)


def raise_for_status(resp: httpx.Response) -> None:
    try:
        resp.raise_for_status()
    except httpx.HTTPStatusError as e:
        code = resp.status_code
        data = convert_response_content(resp)
        if code == 400:
            raise BadRequest(resp, data) from None
        elif code in (401, 403):  # Unauthorized request - Invalid credentials
            raise Unauthorized(resp, data) from None
        elif code == 404:  # not found
            raise NotFoundError(resp, data) from None
        elif code == 429:
            raise RatelimitError(resp, data) from None
        elif code == 503:  # Maintainence
            raise ServerError(resp, data) from None
        else:
            raise UnexpectedError(resp, data) from e


def convert_response_content(resp: httpx.Response) -> Union[Dict, str]:
    try:
        return resp.json()
    except json.JSONDecodeError:
        return resp.text

First it make sure, that the response has a status code 200 <= code < 300. Otherwise it will raise an exception. Is an exception Is raised for you?

If the status code is in the allowed range, it will try to read the json string and convert it to a dict. If this fails, it will return the text. So you should got something (dict, str or exception) but not None.

from audible.

mkb79 avatar mkb79 commented on May 24, 2024

FYI:
I've got a response with the default callback or a 404 exception, if the asin has no bookmarks.

from audible.

GGyll avatar GGyll commented on May 24, 2024

Thanks for sharing your code, I fixed my problem. For some reason my default_response_callback() was like this:

def default_response_callback(resp: httpx.Response) -> Union[Dict, str]:
    return resp.next_request
    raise_for_status(resp)
    return convert_response_content(resp)

The weird thing is I don't remember changing it, just that everything was working then I took a 2 week break and came back and it wasn't, but changing it to your code worked... lol

from audible.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.