This space is a little messy for python. The old urllib ships with python, but it doesn't support some normal expected things like HTTP/1.1 pipelined requests. It adds a "Connection: close" header to each request.
This space is a little messy for python. The old urllib ships with python, but it doesn't support some normal expected things like HTTP/1.1 pipelined requests. It adds a "Connection: close" header to each request.
https://vorpus.org/blog/why-im-not-collaborating-with-kennet...
Here's one discussion about it in the requests repo https://github.com/psf/requests/issues/2424
Coding against a pile of external python modules is perfectly reasonable when you're building something "app scale" -- i.e. something that is going to be spread across many files and installed in a container or venv.
However, when writing something at "script scale" I just don't want to deal with all of that. I want to write something that I can deploy as a single file and not end up dealing with missing python dependencies every time. This means I'm using the old urllib and such more often than I'd like.
It's a shame that there doesn't seem to be much flow of functionality into stdlib at all any more. For my needs, I wish "requests" and "yaml" were in that set, although I'm sure other people have their own opinions on that.
I could look for myself, but it might be more fun as an open discussion topic.
import json
import urllib3
http = urllib3.PoolManager()
data = {'key': 'value'}
encoded_data = json.dumps(data).encode('utf-8')
r = http.request(
'POST',
'http://httpbin.org/post',
body=encoded_data,
headers={'Content-Type': 'application/json'}
)
in requests, it's: import requests
requests.post('http://httpbin.org/post', json={'key': 'value'})Yes, I just didn't in my toy example. That's the response object, which will typically include all the response info, plus reponse.request, which has request info.
> and does it give you the same information to help debug that http.request gives?
I'm not positive, but I'd bet it's similar.
import urllib3
urllib3.request("POST", "https://httpbin.org/post", json={"key": "value"})