登录

python - 远端RESTful API调用

GET /api/accounts HTTP/1.1
Content-Type: application/json
X-Access-Token: username:token

这种 API,Python 要怎么调用啊??
POST 登录生成 token 以后要怎么调用啊??? 求告知

# Python
阿神阿神2146 天前616 次浏览

全部回复(4) 我要回复

  • PHPzhong

    PHPzhong2017-04-17 17:52:10

    import requests
    token = '从你存储的地方取值'
    headers = {
        'Content-Type': 'application/json',
        'X-Access-Token': 'username:{0}'.format(token)
    }
    
    r = request.get('/api/accounts', headers=headers)
    print r.text

    回复
    0
  • PHP中文网

    PHP中文网2017-04-17 17:52:10

    把获得的token保存在本地,每次请求的时候带上token就好了

    回复
    0
  • PHP中文网

    PHP中文网2017-04-17 17:52:10

    import requests

    r = requests.get(url)

    回复
    0
  • 黄舟

    黄舟2017-04-17 17:52:10

    import requests
    r = requests.get(url, cookies=cookies)

    回复
    0
  • 取消回复发送