Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
* Fetching an mbox from lore
@ 2023-07-22 17:12 Maxime Ripard
  2023-07-22 18:47 ` Willy Tarreau
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maxime Ripard @ 2023-07-22 17:12 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: users, tools

[-- Attachment #1: Type: text/plain, Size: 1908 bytes --]

Hi,

I've been trying to fetch an mbox from lore with an arbitrary search request.

I could fetch it fine using curl with the following example:

curl -XPOST -H "Content-Length:0" -OJ "http://lore.kernel.org/linux-clk/?q=d:1.week.ago..&x=m"

This returns a gzip'd mbox, everything's fine.

However, for some reason I can't duplicate it with python's requests
API, and it looks like I get redirected back and forth between HTTPS and
HTTP when I try to connect with the following script:

#!/usr/bin/env python3

from urllib.parse import urlparse

from requests import Request, Session

LORE_URL = "https://lore.kernel.org/linux-clk"

def try_url_redirect(url):
    headers={"Content-Length": "0"}
    params={"q": "d:1.week.ago..", "x": "m"}

    s = Session()

    req = Request('POST', url, headers=headers, params=params)
    p = req.prepare()

    print("Trying to connect to %s" % p.url)

    resp = s.send(p, allow_redirects=False)

    if resp.status_code == 301:
        print("Redirecting to %s" % resp.headers['location'])

        url = urlparse(resp.headers['location'])
        url = url._replace(query="")

        return (resp.status_code, url.geturl())

if __name__ == '__main__':
    code, url = try_url_redirect(LORE_URL)
    try_url_redirect(url)

The output is:

Trying to connect to https://lore.kernel.org/linux-clk?q=d%3A1.week.ago..&x=m
Redirecting to http://lore.kernel.org/linux-clk/?q=d%3A1.week.ago..&x=m
Trying to connect to http://lore.kernel.org/linux-clk/?q=d%3A1.week.ago..&x=m
Redirecting to https://lore.kernel.org/linux-clk/?q=d%3A1.week.ago..&x=m

If I do allow redirects, then requests will issue a GET on the new
location and I'll end up with the HTML webpage of that request.

Am I trying to do something not supported here, or is it supposed to
work and my script is wrong for some reason?

Thanks!
Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-24  8:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-22 17:12 Fetching an mbox from lore Maxime Ripard
2023-07-22 18:47 ` Willy Tarreau
2023-07-22 22:34 ` Rob Herring
2023-07-24  8:07   ` Maxime Ripard
2023-07-23  1:36 ` Eric Wong
2023-07-24  8:06   ` Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox