Python

HTTP & the Web

36 flashcards · answers and spaced-repetition review in the KnowCard app

You call urllib.request.urlopen(url) for a page that returns HTTP 404. What happens?
What is the type of the value returned by reading a urlopen response? ``` import urllib.request r = urllib.request.urlopen(url) data = r.read() ```
You want to GET https://api.example.com/search with q="hello world" and lang="en". How should you build the URL?
Why is requests.get(url, params={...}) preferred over manually pasting the query string into the URL?
What do requests' r.content and r.text return, and when do you use each?
A web API returns JSON. What's the right way to get a Python dict from a urllib response?
How do you send a custom header (e.g. a User-Agent) with urllib.request?
What determines whether urlopen sends a GET vs a POST request?
What does this print? ``` from urllib.parse import quote print(quote("a b/c?d")) ```
Your script hangs forever when a server stops responding. What's the fix?
For real-world HTTP in Python, which library does the official docs recommend over the urllib standard library, and why does it matter?
What does HTTP status code 403 signify, versus 200, 404, and 500?
What's the difference between GET and POST for sending data to a server?
requests.get and requests.post are the familiar ones. Which other HTTP methods does requests expose as functions?
For the query string "hello=world&hello=blah&xyz=12", how do parse_qs and parse_qsl differ in what they return?
base = "http://www.test.com/hello/world.py" and relative = "you.py". What does urllib.parse.urljoin(base, relative) return?
What problem does XML-RPC solve, and why is it easy to implement across many languages?
How do you create an XML-RPC server that binds to every address of the host, and from which module?
How do you expose a Python function for XML-RPC calls, and can the remote name contain a hyphen?
What six components does urllib.parse.urlparse() split a URL into?
You call urllib.request.urlopen("data/report.html") with no scheme in the string. Where does urllib look for that resource?
The object returned by urllib.request.urlopen() looks like a file. What can't you do with it, and what type do its read methods return?
After f = urllib.request.urlopen(url), how do you read the response headers such as Content-Length and Server?
urlopen has no obvious parameter for HTTP Basic auth or routing through a proxy. What mechanism does urllib.request provide?
By convention, what file does a well-behaved web crawler read first, and which urllib module interprets it?
After parts = urllib.parse.urlparse(url), you try parts[6] to get the hostname and it fails. Why, and how do you actually get host/port/username/password?
Does urllib.parse.urlunparse(urlparse(url)) == url always evaluate to True?
You call server.register_instance(obj) on an XML-RPC server. How are the client's remote method calls routed into your object?
register_instance accepts allow_dotted_names. Why should you leave it off outside a trusted network?
By default a client can't introspect a Python XML-RPC server's methods. How does the server opt in, and what does that expose?
On the client side, how do you connect to an XML-RPC server and call its fac() function?
You call system.methodSignature(name) against a Python XML-RPC server. What comes back, and why?
You must call a remote XML-RPC function hundreds of times. How can xmlrpc.client cut the network round-trips?
Your XML-RPC function returns a complex number and the call raises xmlrpc.client.Fault. Why?
You send an instance of your own class over XML-RPC. What arrives on the other side?
XML-RPC has no native way to carry a datetime or raw bytes. Which two xmlrpc.client wrapper types handle them?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play
HTTP & the Web (Python) · KnowCard