El_Cookie 7 Posted December 11, 2024 Posted December 11, 2024 Hello, For context, I'm developing a Telegram bot to manage my users and I've created a button that allows you to authorize or not media playback for a specific user. Except that I have a problem when I disable or re-enable access with my button it also checks “Enable access to all libraries” when I only want to work with the “Allow media playback” function on Emby. Here's an extract of my 2 functions def disable_user_access(emby_user_id: str) -> bool: """ Fonction qui désactive l'accès aux bibliotèque Emby et TV Args: emby_user_id (str): L'ID user à configurer Returns: int: 0 = OK , 1 = Erreur """ headers = {'X-Emby-Token': EMBY_API_KEY, 'Content-Type': 'application/json'} url_policy_user = f'{EMBY_URL}/Users/{emby_user_id}/Policy' user_policy = { 'EnableLiveTvAccess': False, 'EnableMediaPlayback': False } try: response = requests.post(url_policy_user, headers=headers, json=user_policy) response.raise_for_status() # Gère les erreurs HTTP logger.info(f"L'accès aux médias du compte {emby_user_id} a bien été désactivé.") return 0 except requests.exceptions.HTTPError as e: ... def enable_emby_access(emby_user_id: str) -> bool: """ Fonction qui donne accès à un utilisateur membre aux médias Emby Args: emby_user_id (str): L'ID de l'utilisateur Returns: int: 0 = OK, 1 = Erreur """ headers = {'X-Emby-Token': EMBY_API_KEY, 'Content-Type': 'application/json'} url_policy_user = f'{EMBY_URL}/Users/{emby_user_id}/Policy' user_policy = { 'EnableLiveTvAccess': True, 'EnableMediaPlayback': True } try: response = requests.post(url_policy_user, headers=headers, json=user_policy) response.raise_for_status() # Gère les erreurs HTTP logger.info(f"The member plan activated for the ID : {emby_user_id}") return 0 except requests.exceptions.HTTPError as e: ... Is this normal behavior? Thank you for your answers
Luke 42077 Posted December 11, 2024 Posted December 11, 2024 Hi, are you pulling down the user policy, making your changes, and then sending the updated version back?
El_Cookie 7 Posted December 11, 2024 Author Posted December 11, 2024 Hi, No, I just want to push with only this change.
Solution Luke 42077 Posted December 11, 2024 Solution Posted December 11, 2024 OK that's how the api currently works though. It does not accept partial changes like that, so you have to pull down the original object first. The good news though is that some api's in the server are now being updated to accept partial changes like that, but user policy hasn't gotten that yet.
El_Cookie 7 Posted December 11, 2024 Author Posted December 11, 2024 Okay, now I understand. I will modify my code to get the current user policy before then make changes and resend. Thanks for your answer 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now