php - Python RESTful 客户端,例如来自 PHP 的 Guzzle

标签 php python rest guzzle

什么 Python 库提供了 RESTful 客户端接口(interface),例如:

client = Client(
    base_url="http://example.com/api/1/", auth=("user", "password"),
    cookie=cookielib.FileCookieJar('cookie-file'))
result = client.get('group', params={"groupname": "some_group", "expand": "users"})
result.json()

最佳答案

不完全是那样,但你可能想要 requests

编辑:因为您想省略基本 URL,请尝试这样的操作:

base_url = "http://example.com/"
def requests_get(url, *args, **kwargs):
    return requests.get(base_url + url,*args,**kwargs)

另一种解决方案是子类化 requests.Session,如 this answer 所示。 .

关于php - Python RESTful 客户端,例如来自 PHP 的 Guzzle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28478880/

相关文章:

python - Zoho 调用 API 出现问题 {"code":1038 ,"message":"JSON is not well formed»}

python - 使用变量访问 pandas 多索引

java - Restful Web 服务 Maven 项目 netbeans

java - http 的正确 JSON 格式、正确的 JSON 转义宪章

php - PHP 中带有守卫的有限状态机?

php - 1M条记录时优化MySQL数据库select语句 : store old data separately?

php - 按频率对 SQL 查询记录排序

php渲染html表格

python - 获取 Pandas DataFrame 第一列

rest - 使用 URI 与接受 header 进行 REST 内容格式协商的优缺点是什么?