Getting a 401 from requests.get, but not when logging in via the browser.

Eli the Bearded * at eli.users.panix.com
Mon Apr 20 19:35:56 EDT 2020


In comp.lang.python,  <dcwhatthe at gmail.com> wrote:
> On Monday, April 20, 2020 at 5:02:23 PM UTC-4, Eli the Bearded wrote:
> > For an example, back to telnet again.
> > 
> > $ telnet example.com 80
> > Trying 255.11.22.123...
> > Connected to example.com
> > Escape character is '^]'.
> > GET /digest/ HTTP/1.1
> > Host: example.com

FYI, I type in the lines "GET /digest/ HTTP/1.1" and "Host: example.com"
(which should match the name of the site you wish to connect to), then
a blank line. After that the server first begins to "speak".

> > If you don't understand what the site is asking for, it may be very
> > difficult for you to satisfy it.
> Been years since I used Telnet.  I didn't even think that Windows had it
> anymore.

I use it frequently in Linux. But nc or the like works as well for the
way I use it: not for actual "telnet" protocol stuff.

> I tried telneting the landing page, i.e. without the specific node that
> requires the login.  So e.g.
> 
> Telnet thissite.oh.gov 80
> 
> , but it returns a 400 Bad Request.  Before that, the Telnet screen is
> completely blank ; I have to press a key before it returns the Bad
> Request.

It sounds like you are entering a blank line without the GET request
and Host: header.

> Roger on knowing what the site is asking for.  But I don't know how to
> determine that.

Developer tools in your browser may be helpful. As I mentioned, I'm much
better at this at low levels. I haven't kept up with the changes in the
tools over the past decade or so.

If you have an HTTPS site you want to check, the openssl tool can
create an interactive tunnel for you. Command line is more complicated
and output is more verbose, but the gist is similar:

$ openssl s_client -connect example.com:443
[outs of output]
GET /digest/ HTTP/1.1
Host: example.com

[lots of output]

Elijah
------
likes knowing how the pieces fit together


More information about the Python-list mailing list