Comments (5)
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.
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.
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.
FYI:
I've got a response with the default callback or a 404 exception, if the asin has no bookmarks.
from audible.
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)
- 错误提示 HOT 19
- Quality is set to `Extreme` even set to `high` HOT 1
- TEST: New device registration method HOT 4
- Extract Audible Bookmark Notes HOT 3
- Issue getting activation bytes from auth server HOT 9
- Switch to poetry, implement CI+CD, remove Python version <3.8
- Lift upper version restriction on `httpx`. HOT 3
- Is there any way to get a list of books in a series? HOT 1
- Amazon authentication code not handled properly HOT 2
- I need some help with metadata HOT 2
- Audible brazil HOT 11
- Brazil Account Can not login by external_login HOT 3
- RecursionError introduced in 0.9.0 in some cases HOT 3
- API doc: Only High and Normal is allowed as quality
- `valid_mail` regex is too strict HOT 3
- How does the BestSellers sort_by option in the APIs work? HOT 3
- Where does the file get stored with to_file() HOT 5
- Can't filter plus catalog books from 'catalog/products' HOT 9
- state token for library requests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audible.