Weird HTTP response - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: Weird HTTP response (/thread-8448.html) |
Weird HTTP response - league55 - Feb-21-2018 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? RE: Weird HTTP response - abhin - Feb-21-2018 I think you're going to have to provide more information than that. For example:
RE: Weird HTTP response - league55 - Feb-21-2018 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. RE: Weird HTTP response - Larz60+ - Feb-21-2018 code 302 is a redirect. You probably don't allow that with your firewall or virus checker settings. Usually this is a good thing. RE: Weird HTTP response - league55 - Feb-22-2018 Well, I shouldn't have opened that Response object in my browser, because it locked my root account, and I lost all my work. RE: Weird HTTP response - Larz60+ - Feb-22-2018 Quote:I shouldn't have opened that Response object in my browser, because it locked my root accountYour browser did that? or your admin. RE: Weird HTTP response - league55 - Feb-22-2018 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. RE: Weird HTTP response - wavic - Feb-22-2018 There is no way HTML code to lock the root account. Besides requests module doesn't run JavaScript. It's something else. RE: Weird HTTP response - Larz60+ - Feb-22-2018 Requests is python: https://github.com/requests/requests/tree/master/requests |