Skip to main content

Introduction

We want to use APIs from web UIs that require login. What we want to do is to set up a session, login and then use the API of the page. The reason we want to do this is to use existing APIs. For instance, the user group management service at KTH, see 1{reference-type="ref" reference="UGEditor"}. We can then use the service, track the requests in the browser's developer tools. Then we can simply make the same requests from Python.

Screenshot of the KTH UG Editor with Firefox's Developer Tools open, showing network requests made.

For instance, we can redo the request in Figure 1 (above) like this:

import weblogin
import weblogin.kth
import os

ug = weblogin.AutologinSession([
                weblogin.kth.UGlogin(os.environ["KTH_LOGIN"],
                                     os.environ["KTH_PASSWD"],
                                     "https://app.kth.se/ug-gruppeditor/")
            ])

response = ug.get("https://app.kth.se/ug-gruppeditor/api/ug/users"
                  "?filter=memberOf eq 'u26yk1i3'")

The code above will access the API used by the KTH UG group editor service. It will automatically sign in when needed. The API URLs don't trigger a redirect to log in, they just give a 401 unauthorized error. However, we can use the main URL to the UI to trigger such an event, log in and then access the API. All this happens automatically in the background.

The way we do this is to subclass the requests.Session class to intercept all requests of a session to check for signs indicating that we must log in. When we detect such sign, we log in and resume as if nothing ever happened.

Metadata

Release files for weblogin 1.25

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for weblogin 1.25
File Size Uploaded
weblogin-1.25.tar.gz 114.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for weblogin 1.25
File Interpreter ABI Platform
weblogin-1.25-py3-none-any.whl Python 3 none any Details

Total release size: 178.7 kB

Release files / weblogin-1.25.tar.gz

Download URL weblogin-1.25.tar.gz
Size 114.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e51ce8d8531c5998fb158aa0dfa95e59004e4c228b34cc5782653a2026278fad
BLAKE2b-256 checksum
How to use checksums
91ff76aa5cd59e153ed16b3238704e223874cdc9822cb5170720560db0cb0f64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.4 Linux/7.0.0-31-generic

Release files / weblogin-1.25-py3-none-any.whl

Download URL weblogin-1.25-py3-none-any.whl
Size 64.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e824ceb563b892dc366c9379b144d7bb4607f99e8fc78e76e0883a3d3bee458e
BLAKE2b-256 checksum
How to use checksums
43a73a601ff2d30b18eb7337a809a3fb315db56fea02234ea285f23646457d30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.4 Linux/7.0.0-31-generic

Release history Release notifications | RSS feed

This release

1.25 This release

2 release files

1.24

2 release files

1.23

2 release files

1.22

2 release files

1.21

2 release files

1.20

2 release files

1.19

2 release files

1.18

2 release files

1.17

2 release files

1.16

2 release files

1.15

2 release files

1.14

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page