speric/kindle-highlights

mechanize.rb:372:in `click': undefined

jasonhoekstra opened this issue · 13 comments

With:

require 'kindle_highlights'

# pass in your Amazon credentials. Loads your books (not highlights)
# on init, so might take a while
kindle = KindleHighlights::Client.new("email@email.com", "password")

Getting an error message of:

/home/jason/.rvm/gems/ruby-2.3.0/gems/mechanize-2.7.4/lib/mechanize.rb:372:in click': undefined method[]' for nil:NilClass (NoMethodError)
from /home/jason/.rvm/gems/ruby-2.3.0/gems/kindle-highlights-0.0.8/lib/kindle_highlights/client.rb:30:in load_books_from_kindle_account' from /home/jason/.rvm/gems/ruby-2.3.0/gems/kindle-highlights-0.0.8/lib/kindle_highlights/client.rb:10:ininitialize'
from main.rb:5:in new' from main.rb:5:in

'

Any ideas on what I may be doing wrong?

@jasonhoekstra are you passing in your Amazon email/password?

@speric, yes with this code example, actual un/pw used and double checked against Amazon's web interface

I ran this locally on Ruby 2.3.0, using mechanize 2.7.4 (as in your setup) with no problems. I am at a loss.

Ok thanks @speric for helping take a look at the issue. I'll dig into more on my end and see if I can figure this out. Excited about this capability and appreciate the effort.

Sure thing! Please let me know if I can do anything else.

@speric - to close the loop on this one, I was able to get highlight data via the kindle-highlight gem. Once I figured out the problem, books and highlights flowed as expected, quite useful code!

To summarize the issue:

To debug, I logged into Amazon with Chrome Incognito. The issue was an Amazon CAPTCHA dialog presented itself in Incognito, which didn't appear while logging in/out in a usual browser session. After I answered the CAPTCHA in Incognito, the kindle-highlights gem was able to download book and highlights.

In case this is helpful in the future / to the next person!

Thanks!

I encountered this as well, and only realized it was a CAPTCHA after dumping kindle_logged_in_page.body to html and viewing it. I test with Incognito so @jasonhoekstra's solution doesn't work for me.

@jasonhoekstra @speric are you using Windows? I use Chromium on ubuntu. I'm wondering whether amazon's anomaly detection is triggered by a "suspicious" user agent string.

OK, I just modified client.rb, commenting out @mechanize_agent.user_agent_alias = 'Windows Mozilla' and using @mechanize_agent.user_agent = ... using my Chromium's user agent string, and looks like it worked.

@speric would you consider exposing the mechanize setup? Also, it would be helpful to detect the CAPTCHA and fail gracefully. div#ap_captcha_img will match the box with the image.

@whacked I'm using Chrome 48 on MacBook OS X 10.11

@whacked I am certainly open to improving the library to make it more flexible. In this case, to be perfectly honest, I am not sure when I'll have time to implement this specific change. Pull requests are welcome though, if you'd like to give it a shot!

@speric thanks, sent #3

Would be great if you can merge the PR -- I had the same issue and the PR from @whacked worked great for me.