Comments (18)
It looks like an error with the captcha who can’t display correctly.
This codeline is important:
with urllib.request.urlopen(captcha["src"]) as url:
f = io.BytesIO(url.read())
img= Image.open(f)
img.show()
Which is you use and which x-Server you have?
from audible.
A quick workaround:
Change the obove lines of code to:
with urllib.request.urlopen(captcha["src"]) as url:
f = io.BytesIO(url.read())
try:
img= Image.open(f)
img.show()
execept:
print(f)
On error audible-api now printes you the url for captcha on screen and you have to open the link with a webbrowser.
from audible.
Sorry there is a error in my code. Correct is:
with urllib.request.urlopen(captcha["src"]) as url:
f = io.BytesIO(url.read())
try:
img= Image.open(f)
img.show()
execept:
print(captcha["src"])
from audible.
Can you please update audible with pip update audible
and try again.
from audible.
pip install --upgrade audible
Collecting audible
Downloading https://files.pythonhosted.org/packages/23/ca/0c3822c159ed9f0b1e2900fe27a6d368f1dd4904aa1a7db6743e726357a2/audible-0.1.3-py3-none-any.whl
Requirement already satisfied, skipping upgrade: beautifulsoup4 in /usr/local/lib/python3.6/site-packages (from audible) (4.7.1)
Requirement already satisfied, skipping upgrade: Pillow in /usr/local/lib/python3.6/site-packages (from audible) (6.0.0)
Requirement already satisfied, skipping upgrade: rsa in /usr/local/lib/python3.6/site-packages (from audible) (4.0)
Requirement already satisfied, skipping upgrade: requests in /usr/local/lib/python3.6/site-packages (from audible) (2.21.0)
Requirement already satisfied, skipping upgrade: soupsieve>=1.2 in /usr/local/lib/python3.6/site-packages (from beautifulsoup4->audible) (1.8)
Requirement already satisfied, skipping upgrade: pyasn1>=0.1.3 in /usr/local/lib/python3.6/site-packages (from rsa->audible) (0.4.5)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/site-packages (from requests->audible) (3.0.4)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests->audible) (2.8)
Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests->audible) (1.24.1)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests->audible) (2019.3.9)
Installing collected packages: audible
Found existing installation: audible 0.1.2
Uninstalling audible-0.1.2:
Successfully uninstalled audible-0.1.2
Successfully installed audible-0.1.3
Just installed the new version from pip.
I am not running an x-server my use case needs me to get it running on a headless machine.
That is... I think..., once I've read over the errors again... I've pinpointed the problem. DOH!
Is there any ways to print out the URL so I can open and enter it manually?
Like a check or something that detects if the machine is running without a x-server if so, go strictly text based?
from audible.
I have released version 1.4 on pypi now. Please update again.
How you execute the script? Tru a ssh session? Then you have the output in console and you can try following code:
import audible
def custom_captcha_callback(captcha_url):
print(captcha_url)
guess = input("Answer for CAPTCHA: ")
guess = str(guess).strip().lower()
return guess
client = audible.Client("EMAIL", "PASSWORD", local="us", captcha_callback=custom_captcha_callback)
Now the Captcha url will be prompted in your ssh console and you can copy&past them to a Webbrowser and insert captcha answer in console.
from audible.
If you have success don’t forget to save session. Otherwise you can try to execute the script on a local machine and save session to file. Then you can store the session file in project folder on your headless machine and init a session with
client = audible.Client(filename="your filename", local="us")
from audible.
success!
Still not sure how to save a session tho, right now I have to type in a Captcha each time I call the script.
The last snip of code you shared is for loading a saved session. How do I go about saving the session to begin with?
Once I get that figured out, I should be able to put the pieces together from there.
import audible
def custom_captcha_callback(captcha_url):
print(captcha_url)
guess = input("Answer for CAPTCHA: ")
guess = str(guess).strip().lower()
return guessclient = audible.Client("MYUSERNAME", "MYPASSWORD", local="us", captcha_callback=custom_captcha_callback)
library = client.get("library/books", api_version="0.0", purchaseAfterDate="01/01/1970", sortInAscendingOrder="true")
print(library)
I'm just executing a script through a ssh session.
Basically: python3.6 test.py
Another quick question, does the local="us" also work with the audible.ca ? the canadian version? I seemed to be getting the results from my library, so I think it is?...
from audible.
In the README I wrote how to save session. Here are two examples:
# give filename at instantiate client
# saves session after success init and register device
client = audible.Client(..., filename="your filename or path+filename")
# saves at any moment
client = audible.Client(...)
client.to_json_file(filename or path+filename)
Hint:
You are using deprecated version of library call. This is the new one:
client.get(
"library",
num_results=999,
response_groups="media, series, ..."
)
Canadian is not supported but can be implemented very easy.
from audible.
! Got it working, just needed to add filename="FILENAME",
then load it with the snip of code you posted earlier.
from audible.
I don’t know if you can use an session file from us store to call canadian audible api.
I have add canadian now to my code but will them upload later. In germany it‘s now 1am.
Meanwhile you can open the localization.py delivered by audible module and rewrite to:
from urllib.parse import urlparse
localization = {
"de": {
"AMAZON_LOGIN": urlparse("https://www.amazon.de"),
"AMAZON_API": urlparse("https://api.amazon.de"),
"AUDIBLE_API": urlparse("https://api.audible.de"),
"Accept-Language": "de-DE",
"marketPlaceId": "AN7V1F1VY261K",
"openid_assoc_handle": "amzn_audible_ios_de",
"oauth_lang": "de-DE",
"auth_register_domain": ".amazon.de"
},
"us": {
"AMAZON_LOGIN": urlparse("https://www.amazon.com"),
"AMAZON_API": urlparse("https://api.amazon.com"),
"AUDIBLE_API": urlparse("https://api.audible.com"),
"Accept-Language": "en-US",
"marketPlaceId": "AF2M0KC94RCEA",
"openid_assoc_handle": "amzn_audible_ios_us",
"oauth_lang": "en-US",
"auth_register_domain": ".amazon.com"
},
"uk": {
"AMAZON_LOGIN": urlparse("https://www.amazon.co.uk"),
"AMAZON_API": urlparse("https://api.amazon.co.uk"),
"AUDIBLE_API": urlparse("https://api.audible.co.uk"),
"Accept-Language": "en-GB",
"marketPlaceId": "A2I9A3Q2GNFNGQ",
"openid_assoc_handle": "amzn_audible_ios_uk",
"oauth_lang": "en-GB",
"auth_register_domain": ".amazon.co.uk"
},
"fr": {
"AMAZON_LOGIN": urlparse("https://www.amazon.fr"),
"AMAZON_API": urlparse("https://api.amazon.fr"),
"AUDIBLE_API": urlparse("https://api.audible.fr"),
"Accept-Language": "fr-FR",
"marketPlaceId": "A2728XDNODOQ8T",
"openid_assoc_handle": "amzn_audible_ios_fr",
"oauth_lang": "fr-FR",
"auth_register_domain": ".amazon.fr"
},
"ca": {
"AMAZON_LOGIN": urlparse("https://www.amazon.ca"),
"AMAZON_API": urlparse("https://api.amazon.ca"),
"AUDIBLE_API": urlparse("https://api.audible.ca"),
"Accept-Language": "en-CA",
"marketPlaceId": "A2CQZ5RBY40XE",
"openid_assoc_handle": "amzn_audible_ios_ca",
"oauth_lang": "en-CA",
"auth_register_domain": ".amazon.ca"
},
}
And then you can
import audible
client = audible.Client(User, Password, local="ca", filename="your filename", captcha_callback="your captcha function here")
from audible.
I just tried it, yes you can use a session file from the US to call the Canadian api. It worked for me.
I just tweaked my localization file manually here. I'll pull in the changes with pip later when you update. Have a good night!
from audible.
That sounds great. Can you try follow code and tell me in what currency the prices are?
client.get(
"library",
num_results=999,
response_groups="price"
)
If the prices are in CAD all is fine. But if they in USD you need a new session file from ca store.
from audible.
Ok, I setup a little test. Using my session-us.key (the session key generated using local="us")
Running the code snippet above against each localization:
de -> {'items': [], 'response_groups': ['always-returned', 'price']}
us -> 'currency_code': 'USD'
uk -> {'items': [], 'response_groups': ['always-returned', 'price']}
fr -> {'items': [], 'response_groups': ['always-returned', 'price']}
ca -> 'currency_code': 'CAD'
So I can conclude that my session-key works for the us local and the ca local. However for the de, uk, fr local I get those responses.
I think this might be the case because I have never bought anything from those other 3 stores, so I have no data returned.
As a side note, whats the best way to parse the data returned from each api call? is it JSON formatted?
from audible.
Thanks for your help. The response type is a python dictionary.
from audible.
I must correct me. The api answer is in json. But this app converted them to a python dictionary.
from audible.
No problem, if I can help with anything let me know.
Python Dictionary! I never would have guessed... I was trying to parse them as json and it just wasn't working... was starting to pull my hair out...
from audible.
First I thought to output the response as json. But as json you can‘t work correctly with the response. So I have decided me to output the response as a 'classic' python dictionary. I would close this issue now.
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
- response_callback no longer works properly with the endpoint: https://cde-ta-g7g.amazon.com/FionaCDEServiceEngine/sidecar HOT 5
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.