lazeroffmichael / ticktick-py

Unofficial TickTick API
https://lazeroffmichael.github.io/ticktick-py/
MIT License
215 stars 31 forks source link

Login fails with response 429 #53

Closed Factual0367 closed 7 months ago

Factual0367 commented 8 months ago

I have followed the instructions in the README. Although the auth-token is received successfully, authorization fails with error code 429. Any idea what the problem is?

VictorOV commented 8 months ago

The same problem

btw04 commented 8 months ago

Fixed in #54. The only thing that needs to change is the firefox version in the request header as that was too outdated

random25252 commented 8 months ago

Thanks again @btw04 your fixes over the past few years have been terrific for those of us using the library long term but not familiar enough with the codebase to fix it ourselves. For those like me, before the pull request is merged in, you can just add the code that btw04 modified before the ticktickclient is initialized and this will overwrite the variables accordingly and seems to work for me. EG:

USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0"
X_DEVICE_ = '{"platform":"web","os":"OS X","device":"Firefox 123.0","name":"unofficial api!","version":4531,' \

TickTickClient.HEADERS = {'User-Agent': USER_AGENT,
               'x-device': X_DEVICE_}

For me at least, this is easier than editing the api.py file that's part of the library.

berezovskyi commented 7 months ago

For me just patching headers didn't work, I needed to update the endpoint:

class TickTickClientPatched(TickTickClient):
    def _login(self, username: str, password: str) -> None:
        """
        Logs in to TickTick and sets the instance access token.

        Arguments:
            username: TickTick Username
            password: TickTick Password

        """
        url = self.BASE_URL + 'user/signon?wc=true&remember=true'
        user_info = {
            'username': username,
            'password': password
        }
        parameters = {
            'wc': True,
            'remember': True
        }

        response = self.http_post(url, json=user_info, params=parameters, headers=self.HEADERS)

        self.access_token = response['token']
        self.cookies['t'] = self.access_token

client = TickTickClientPatched(
    os.getenv("TICKTICK_USERNAME"), os.getenv("TICKTICK_PASSWORD"), auth_client
)
DougX71 commented 7 months ago

I am wondering about the policy of when to mark an issue as closed. One approach is to close the issue when the cause is known and a workaround is available. Another approach would be to only close it when code fixes are reflected in the version that new users install. The default in GitHub is that only open issues are displayed. A new user could install the app, have a problem then look into the list of open issues and not see the appropriate issue in GitHub. For this reason I favour the second approach of only closing the issue when code fixes are reflected in the version that new users install.