pyLast can make authentication requests while constructing a network object if enough login information is supplied. To configure the route first, create the network without triggering that authentication flow.

The following uses pyLast 5.5's proxy-URI interface and public web-authentication helper:

import pylast

network = pylast.LastFMNetwork(api_key=api_key, api_secret=api_secret)
network.enable_proxy('http://proxy.example.net:8080')

generator = pylast.SessionKeyGenerator(network)
authorization_url = generator.get_web_auth_url()

The application supplies its API key and secret. For a public Last.fm API route that permits unauthenticated intermediaries, use an endpoint from the HTTP proxy list in enable_proxy; those endpoints do not supply the provider credentials. The last call retrieves the authentication token through the configured network object. Ask the user to open the resulting URL and authorize the application.

After authorization, use the same generator to obtain the session key:

network.session_key = generator.get_web_auth_session_key(authorization_url)

The generator retains the token associated with that URL. Keeping the same network and generator across these two steps preserves the configured route and the pending authentication state.

When a key already exists

If a session key is already stored, supply it as session_key when the network is created, then enable the proxy before the first API call. The constructor need not request another key. Read-only lookups can likewise use the configured network without starting this authorization flow.

Winndannde jowitiiɗe heen