Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weird HTTP response
#1
I'm putting this in Bar because it's not strictly Python-related, even though I used requests.get().

I got a HTTP Response Code 302 with the following Response.headers content:

'Accept-Ranges': 'bytes', 'Server': 'nginx', 'Vary': 'Accept-Encoding', 'Connection': 'keep-alive', 'X-Origin-Server': 'ocelot-green-2515826831-hwmdw__active_cache', 'Date': 'Wed, 21 Feb 2018 00:42:04 GMT', 'Cache-Control': 'private, max-age=60', 'Content-Length': '24416', 'x-cloud-trace-context': '8b9e248af83a6556acb78260c3b82e0a/15832939404520912928;o=0', 'Expires': 'Wed, 21 Feb 2018 00:43:04 GMT', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html; charset=utf-8'}
The Response.text renders as a perfectly normal-looking html webpage and displays fine in my browser, so it doesn't appear that the request was redirected.

What do you suppose happened here?
Reply
#2
I think you're going to have to provide more information than that. For example:
  • Can we see the actual Python code for making the request?
  • How did you figure out that the request wasn't redirected? Displays fine in my browser is not enough to prove that.
  • How did you establish that "The Response.text renders as a perfectly normal-looking html webpage ...". Did you dump Response.text into a file and open it in a browser or did you just go to the URL in your browser?
  • What's the output of curl -v <enter your URL here>?
Reply
#3
I saved the Response object as an html file and opened it in my browser. Here's the code I used to make the request:

def get_response(url):
    """Obtains Response object from page at url, with error-checking.

        :url:           Url accessed.

        :returns:       Response object.
    """
    try:
        response = requests.get(url, headers=HEADER, timeout=TIMEOUT)
        print("Response code: {}.".format(response.status_code))
        try:
            response.raise_for_status()
        except Exception as HTTPerror:
            print("HTTP error on url {}: {}.".format(url, HTTPerror))
        return response
    except Exception as error:
        print("Error in get_response(): {}.".format(error))
Would loading the response object into a Python script permit me to access all of its methods and attributes, now that I've saved it as an html file using "bw" and encode("utf-8). If that's the case, I can just upload the object somewhere and give you a password to download it.

Thanks for your help.
Reply
#4
code 302 is a redirect.
You probably don't allow that with your firewall or virus checker settings.
Usually this is a good thing.
Reply
#5
Well, I shouldn't have opened that Response object in my browser, because it locked my root account, and I lost all my work.
Reply
#6
Quote:I shouldn't have opened that Response object in my browser, because it locked my root account
Your browser did that? or your admin.
Reply
#7
It's a home system and I'm the "admin" (meaning I set the root password when I installed the OS). I'm pretty sure that, when I opened the saved Response object as an html file and then opened it in my browser to inspect it, it planted malware on my system that locked my root account.

But I reinstalled and haven't so far seen signs of identity theft, financial fraud on my financial accounts, or anything like that. So it could be that I tried to create a subversion repo and put some crap in the /var folder through errors. That could have led to the OS automatically locking the root account.
Reply
#8
There is no way HTML code to lock the root account. Besides requests module doesn't run JavaScript. It's something else.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
Requests is python: https://github.com/requests/requests/tre...r/requests
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020