Preferably using the requests library
HTTP/1.1 200 OK <-- I want this...
Content-Type: text/html; charset=utf-8
That property doesn't seem to be provided http://docs.python-requests.org/en/master/api/#requests.Response
Is there a way to access the raw response string?
I found http://docs.python-requests.org/en/master/user/quickstart/#raw-response-content but I'm not seeing any content
r = requests.head(uri, stream=True)
print(r.raw.read(10)) # -> b''
In this article, you will learn about the Python Requests library, which allows you to send HTTP requests in Python.
The Requests library is available for both Python 2 and Python 3 from the Python Package Index (PyPI), and has the following features: Allows you to send HTTP/1.1 PUT, DELETE, HEAD, GET and OPTIONS requests with ease.
urllib. urllib is a module built into the Python standard library and uses http. client which implements the client side of HTTP and HTTPS protocols.
The requests library is the de facto standard for making HTTP requests in Python. It abstracts the complexities of making requests behind a beautiful, simple API so that you can focus on interacting with services and consuming data in your application.
The requests library is the de facto standard for making HTTP requests in Python. It abstracts the complexities of making requests behind a beautiful, simple API so that you can focus on interacting with services and consuming data in your application.
To reiterate, Requests is a Python library. The good news is that there are a few ways to install the Requests library. To see the full list of options at your disposal, you can view the official install documentation for Requests here. You can make use of pip, easy_install, or tarball.
Source code: Lib/urllib/request.py The urllib.request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. The Requests package is recommended for a higher-level HTTP client interface.
Requests for python3 uses urllib3. Urllib3's class urllib3.response.HTTPResponse is backwards compatible with httplib’s HTTPResponse see urllib3 docs Now if it's backwards compatible you have to check documentation for httplib and if you search you'll find HTTP protocol version used by server. 10 for HTTP/1.0, 11 for HTTP/1.1.
I think what you want is this. Calling version on raw will give you HTTP version. (I found the example of server running HTTP 1.0 using Shodan for testing purposes)
>>> import requests
>>> response = requests.get("http://104.71.136.252/", timeout=60, verify=False)
>>> response.raw.version
10
>>> response = requests.get("http://stackoverflow.com", timeout=60, verify=False)
>>> response.raw.version
11
This is not mentioned in the docs directly, I found it by using PyCharm's autocomplete feature. But I have looked into it. The reason why is HTTP version returned as integer is historical.
Requests for python3 uses urllib3. Urllib3's class urllib3.response.HTTPResponse is backwards compatible with httplib’s HTTPResponse see urllib3 docs
Now if it's backwards compatible you have to check documentation for httplib and if you search you'll find
HTTP protocol version used by server. 10 for HTTP/1.0, 11 for HTTP/1.1.
Here is the exact link HTTPResponse.version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With