Skip to content

Instantly share code, notes, and snippets.

@mcarlton00
Last active July 11, 2025 17:10
Show Gist options
  • Save mcarlton00/f7bd7218828ed465ce0f309cebf9a247 to your computer and use it in GitHub Desktop.
Save mcarlton00/f7bd7218828ed465ce0f309cebf9a247 to your computer and use it in GitHub Desktop.
Example for authenticating to Jellyfin API from Python
import requests
# Define connection details
server_url = 'http://192.168.0.200:8096'
username = 'User'
password = 'Password'
# Build json payload with auth data
auth_data = {
'username': username,
'Pw': password
}
headers = {}
# Build required connection headers
authorization = 'MediaBrowser Client="other", Device="my-script", DeviceId="some-unique-id", Version="0.0.0"'
headers['Authorization'] = authorization
# Authenticate to server
r = requests.post(server_url + '/Users/AuthenticateByName', headers=headers, json=auth_data)
# Retrieve auth token and user id from returned data
token = r.json().get('AccessToken')
user_id = r.json().get('User').get('Id')
# Update the headers to include the auth token
headers['Authorization'] = f'{authorization}, Token="{token}"'
# Requests can be made with
#requests.get(f'{server_url}/api/endpoint', headers=headers)
@EnderRobber101
Copy link

Thanks! I was trying to use the api key but eventually came back to this.

@sortedcord
Copy link

Thanks! I was trying to use the api key but eventually came back to this.

Did you ever get it to work; With the api key? Although username and password is the simplest, I'd rather not deal with passwords

@EnderRobber101
Copy link

No, it was too difficult. The login was a better option for my project to begin with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment