pycaching icon indicating copy to clipboard operation
pycaching copied to clipboard

Logging in to geocaching.com not working (Captcha problem)

Open gotiniens opened this issue 5 years ago • 5 comments
trafficstars

as discussed @ https://github.com/cgeo/cgeo/issues/9056

The login page of geocaching.com for some IP's adds an Captcha, when this happens pycaching fails with

    raise LoginFailedException("Cannot login to the site "
pycaching.errors.LoginFailedException: Cannot login to the site (probably wrong username or password).

A solution is to use an different IP, but that is sometimes easier said than done.

gotiniens avatar Sep 25 '20 20:09 gotiniens

I just had a quick look at the c:geo discussions on this issue. At the moment there are two possible solutions for this:

  • At least report a dedicated error message if a captcha is required. This would not solve the issue itself, but would make more clear what went wrong.
  • Allow the user to pass its own login cookie data (which would require some experience from the user).

FriedrichFroebel avatar Sep 26 '20 10:09 FriedrichFroebel

If the second point is a problem depends on the use case. for my use case: I just want to process some data for my own trackable. The code will probally not be released to the public. Passing the login cookie data will not be a problem

gotiniens avatar Sep 26 '20 10:09 gotiniens

The Geocaching class seems to support passing session objects already, where you could provide the corresponding cookies. But it seems like the login method and the actual request handlers cannot handle this case for now - feel free to submit a fix for this.

FriedrichFroebel avatar Sep 26 '20 11:09 FriedrichFroebel

I have an working proof of concept in my forked repo: https://github.com/gotiniens/pycaching/tree/feature-use-token-for-requests

Do you care to give any further hints en tips before I create an merge request? Usage is very simple, instead of the normal pycaching.login(username, password) to initialize an geocaching object you use pycaching.login_with_token(token) to initialize the object.

You can get the token from the cookiestorage of your browser, it is the cookie called pskauth.

potentianly I have to add some handling for when the cookie is expirded and we get presented an new cookie. But I have been using my current token for a couple of weeks now, with no problem.

gotiniens avatar Dec 27 '20 12:12 gotiniens

I somehow missed your last comment and just stumbled upon it when going through some of the open issues.

It usually is much easier if we discuss the remaining details inside the pull request when the corresponding code is directly visible. So please open a pull request if you are still interested in providing the enhancement.

What I have seen for now and probably should be changed:

  • Please add some logging like in the regular login method.
  • Why is the token nullable? This does not make much sense as we do not allow loading it from a file as for the username and password.
  • Please add a check for an already logged in user as for the regular login method.
  • The code style check will probably report some issues.
  • Maybe add some documentation on which cookie value to pass.
  • Is there some way for you to validate the correct behaviour through an automated test?

FriedrichFroebel avatar Feb 24 '22 20:02 FriedrichFroebel