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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weblogin-1.22.tar.gz (72.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weblogin-1.22-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file weblogin-1.22.tar.gz.

File metadata

  • Download URL: weblogin-1.22.tar.gz
  • Upload date:
  • Size: 72.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-35-generic

File hashes

Hashes for weblogin-1.22.tar.gz
Algorithm Hash digest
SHA256 bbbc6a47bcbaa0a483a1932005b8ab1e6b7fef4ce12756cff73e08f0ef20935a
MD5 92cb1bc39f690b73c6ff787427a07264
BLAKE2b-256 8628919cbf58d760ec6ff352daf5ab68fbf2fa8edab2f0a00e6840bd6edfee00

See more details on using hashes here.

File details

Details for the file weblogin-1.22-py3-none-any.whl.

File metadata

  • Download URL: weblogin-1.22-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.7 Linux/6.17.0-35-generic

File hashes

Hashes for weblogin-1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 06471c6970e131f1e06f1840431e9296d508e4850ad91c43332016a877f1fa24
MD5 7c270a6e5b490053c242db2fed5bd39f
BLAKE2b-256 0527c4b4839c4edbd5f83e340a5d10a9559a953bbe0d7f90a6ea018c8e4f89a1

See more details on using hashes here.

Release history Release notifications | RSS feed

1.23

2 files

This release

1.22 This release

2 files

1.21

2 files

1.20

2 files

1.19

2 files

1.18

2 files

1.17

2 files

1.16

2 files

1.15

2 files

1.14

2 files

1.13

2 files

1.12

2 files

1.11

2 files

1.10

2 files

1.9

2 files

1.8

2 files

1.7

2 files

1.6

2 files

1.5

2 files

1.4

2 files

1.3

2 files

1.2

2 files

1.1

2 files

1.0

2 files

0.4

2 files

0.3

2 files

0.2

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page