0

Before you mark this as a duplicate of this question, here me out...

I am making a POST request to http://my-local-server:80/apistuff/user' to create a user. When I walk through with a debugger, right up until the actual requests.post()`, that URL is http.

But when I look at the Response.url, it says https://my-local-server/apistuff/user. Requests automatically made it an https URL. But there is a problem with this I'll explain in a moment.

The answer to the other question was to add , verify=False as an argument to the post call. But that only says don't verify the certificates; it still changes the URL, and more to my point, it changes THE PORT.

The app thinks it's making a call out on port 80, but it's really sent out on 443. The api does some some stuff--calls an external file with parms--which then sends the reply to the configured url. The configuration says the app is running on port 80, which is important for other sections of the code. So the api tries sending back the response from port 443 (because that's where it came from) to port 80 (because that is where it's directed to).

From this, I've gotten 308 (redirect) errors, 400 (bad request) errors, and 500 (server bad) errors depending on setup.

So verifying certs is not the problem. The problem is that it changed the url/port so it can no longer communicate back.

So the question remains: how do you send something through requests so it STAYS an http request?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MivaScott
  • 1,763
  • 1
  • 12
  • 30
  • If the web server is configured to redirect http traffic to https, it **doesn't matter** whether you set `verify = false`, your request is going to be redirected. It takes two to tango here, your request is only half the picture. – Jared Smith Aug 10 '23 at 18:36
  • 1
    @JaredSmith, the server isn't set to redirect to https. If you hit http, it stays http. – MivaScott Aug 10 '23 at 20:44
  • It doesn't sound like an actual 302 redirect, but try __allow_redirects=False__ just in case? – Kenny Ostrom Aug 11 '23 at 13:33
  • @KennyOstrom, I tried both `allow_redirects=True` and `allow_redirects=False`, but still get the 308 error. My suspicion is that the redirect isn't from the call I'm making but from the call using the config properties. – MivaScott Aug 11 '23 at 17:30

0 Answers0