So default parameters in Python are shared between function calls if it isn’t passed from caller. So be careful because shared mutable object can affect your logic between function calls, where MAGIC was born !
One safe way to achieve the goal, use None as replacement like this
1 2 3 4 5 6 7 8 9 10 11 12
defappend_if_multiple_of_five(number, magical_list=None): ifnot magical_list: magical_list =  if number % 5 == 0: magical_list.append(number) return magical_list
The sophisticated http client in Python is requests, it has simple API but powerful features. You can use it for crawling, sending request to third-party API or writing tests.
Btw, at this moment it doesn’t support HTTP/2 protocol (actually we often doesn’t need its Server Push or Multi resource stream features). But sometime the API endpoint only supports HTTP/2 like Akamai Load Balacing service.
The hero is new library named hyper, it has been developing to support full HTTP/2 specs. But if all we need is requesting single request to a HTTP/2 server. It works like a charm.
$ pip install requests $ pip install hyper
1 2 3 4 5 6 7
import requests from hyper.contrib import HTTP20Adapter s = requests.Session() s.mount('https://', HTTP20Adapter()) r = s.get('https://cloudflare.com/') print(r.status_code) print(r.url)
This mean any url has prefix https:// will be hanlded by HTTP20Adaper of hyper library
If you run above example, you will see the result
While you expected it would auto-follow redirect to the page https://www.cloudflare.com/
We can fix it by using the newer version than 0.7.0 to fix the header key bytestring issue