1

So I want to get a list of response codes (Not to harcode it) from a library.

In python2 I could easily do something like this:

import httplib
....
if res.status_code != httplib.OK:
     do_something

httplib is not present in python3 (I think I hhtp.client is in python3?)

Is there a library compatible with both Python2 and 3 to read the avaialble status codes?

3
  • I have to ask, what is this for? Commented Aug 3, 2017 at 22:23
  • Have you considered requests? Commented Aug 3, 2017 at 22:26
  • six.moves.http_client.OK Commented Aug 3, 2017 at 22:29

2 Answers 2

2
try:
   import httplib as client
except:
   from http import client

#do some stuff here 
Sign up to request clarification or add additional context in comments.

Comments

1

Personally, I like to use requests.

import requests

some_request = requests.get('some link')
some_request.raise_for_status()
# Rest of the code

As per the documentation, an error will only be raised if a request is unsuccessful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.