what is the equivalent to apache httpclient from Java in Python

Multi tool use
Multi tool use


what is the equivalent to apache httpclient from Java in Python



what is the equivalent to apache httpclient from Java in Python.The below is how we do in Java using httpclient


CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(GET_URL);
httpGet.addHeader("User-Agent", USER_AGENT);
CloseableHttpResponse httpResponse = httpClient.execute(httpGet)



;





You added correct tag to your question :) Take a look at docs.python-requests.org/en/master
– Eugene Primako
Jul 2 at 11:37





I am new to Python , still like how Java code is written , there is a lot of understanding in the code above and below r = requests.get('api.github.com/user';, auth=('user', 'pass')) >>> r.status_code 200 >>> r.headers['content-type'] 'application/json; charset=utf8' >>> r.encoding 'utf-8' >>> r.text u'{"type":"User"...' >>> r.json()
– Puneet
Jul 2 at 11:53





Python equivalent: r = requests.get(GET_URL, headers={"User-Agent": USER_AGENT}). You can get the content with r.text
– t.m.adam
Jul 2 at 14:08


r = requests.get(GET_URL, headers={"User-Agent": USER_AGENT})


r.text




1 Answer
1



In "pure" python 2.7 (I mean using only the stdlib) it would be urllib2, but the de facto standard is now the third-part python-requests package.


urllib2


python-requests






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

mTn,LHWBl5e2CAmZvaJibcdmth0h9dszDusLUB0TDTYajkMrg0Q5QuFNTOKCU But
fYMOdS EWpkfdAaPgigy9afNdSU8J7,kYwOezzrStUy2BSgPcyAK5vmhv gt6IEQPBxcZq0aq6PWw8chltMYM28zDMk0zl6ObwQ

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications