Response 403: You don't have the permission to access the requested resource. It is either read-protected or not readable by the server #8

Open
opened 2024-04-21 10:46:36 +02:00 by Michael Mussato · 1 comment

I get 403 if I try to populate Watchtower with Kitsu data.

<Response [403]>
{'message': "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server."}

This fixes it:

@dataclass
class KitsuClient:
    """Client to query the Kitsu API."""

    config: Config
    jwt: str = None
    session = requests.Session()

    @property
    def headers(self):
        return {'Authorization': f"Bearer {self.jwt}"}

    @property
    def base_url(self):
        return self.config.base_url

    def get(self, path, params=None):
        return self.session.get(
            f"{self.base_url}{path}", params=params, headers=self.headers, allow_redirects=True
        )

    def fetch_jwt(self, email, password) -> str:
        payload = {
            'email': email,
            'password': password,
        }
        r_jwt = self.session.post(f"{self.config.base_url}/auth/login", data=payload)
        r_jwt = r_jwt.json()
        if 'error' in r_jwt:
            logging.error(r_jwt['message'])
            exit()
        return r_jwt['access_token']

    def __post_init__(self):
        self.jwt = self.fetch_jwt(self.config.email, self.config.password)
I get 403 if I try to populate Watchtower with Kitsu data. ``` <Response [403]> {'message': "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server."} ``` This fixes it: ``` @dataclass class KitsuClient: """Client to query the Kitsu API.""" config: Config jwt: str = None session = requests.Session() @property def headers(self): return {'Authorization': f"Bearer {self.jwt}"} @property def base_url(self): return self.config.base_url def get(self, path, params=None): return self.session.get( f"{self.base_url}{path}", params=params, headers=self.headers, allow_redirects=True ) def fetch_jwt(self, email, password) -> str: payload = { 'email': email, 'password': password, } r_jwt = self.session.post(f"{self.config.base_url}/auth/login", data=payload) r_jwt = r_jwt.json() if 'error' in r_jwt: logging.error(r_jwt['message']) exit() return r_jwt['access_token'] def __post_init__(self): self.jwt = self.fetch_jwt(self.config.email, self.config.password) ```

Thank you! Could you create a PR for this?

Thank you! Could you create a PR for this?
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: studio/watchtower#8
No description provided.