吁,终于停止了。

HTTPie
HTTPie实用于欲望快速与HTTP办事器、RESTful API 和 Web 办事进行交互的开辟人员,它仅仅须要一行代码。 这个库是“一个可以让你微笑的开源 CLI HTTP客户端:用户友爱的 curl 替代筹划”。固然它可以不依附Python情况,然则它可以经由过程Pip安装,并用来创建HTTP请求。
- pip install httpie
- import json
- from pprint import pprint
- from octopus import Octopus
- def create_request(urls):
- data = []
- otto = Octopus(
- concurrency=4, auto_start=True, cache=True, expiration_in_seconds=10
- )
- def handle_url_response(url, response):
- if "Not found" == response.text:
- print ("URL Not Found: %s" % url)
- else:
- data.append(response.text)
- for url in urls:
- otto.enqueue(url, handle_url_response)
- otto.wait()
- json_data = json.JSONEncoder(indent=None,
- separators=(',', ': ')).encode(data)
- return pprint(json_data)
- print(create_request(['https://api.spotify.com/v1/search?type=artist&q=snoop',
- 'https://api.spotify.com/v1/search?type=artist&q=dre']))
默认协定是HTTP,但您可以创建一个别号,并重置HTTPS为默认值,如下所示:
- alias https='http —default-scheme=https'
之后创建请求:
- https "https://api.spotify.com/v1/search?type=artist&q=snoop"
应用HTTPie仅须要URL就够了。

最后的设法主意
Python 生态供给了很多与 JSON api 交互的选择。固然这些办法对于最简单的请求是类似的, 但跟着 HTTP 请求的复杂性增长, 这些差别变得加倍明显。多进行测验测验, 看看哪一个最合适你的需求。你甚至可以测验测验用另一种说话, 如 Ruby。
推荐阅读
本文总结推荐22个免费的数据可视化和分析对象。列表如下:数据清理(Data cleaning)当你分析和可视化数据前,常须要“清理”工作。比如一些输人道列表“New York City&rdqu>>>详细阅读
地址:http://www.17bianji.com/lsqh/37062.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示