megaman1970

joined 1 year ago
[โ€“] megaman1970@lemmy.world 2 points 1 year ago

Cool. Then my other answer is correct. I appreciate the help!

[โ€“] megaman1970@lemmy.world 7 points 1 year ago (1 children)

Okay, before I head off to bed, I think this works for the login and authentication token:

import requests
import json

def login(username_or_email, password):
    # Define the URL for the login endpoint
    url = "https://lemmy.ml/api/v1/user/login"

    # Define the headers for the request
    headers = {'Content-Type': 'application/json'}

    # Define the data for the login
    data = {
     "username_or_email": username_or_email,
     "password": password
    }

    # Send the POST request
    response = requests.post(url, headers=headers, data=json.dumps(data))

    # Extract the JWT from the response
    jwt = response.json().get('jwt')

    return jwt

# Use the login function
jwt = login("your_username_or_email", "your_password")
print(jwt)

The JSON Web Token (jwt) should contain the authentication token. At least I think that's the case. I picked this out by reading through the Go code at the following URL: https://github.com/Elara6331/go-lemmy/blob/master/lemmy.go

I'll play around with the code later.