search

Home  >  Q&A  >  body text

python - 远端RESTful API调用

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

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

阿神阿神2871 days ago915

reply all(4)I'll reply

  • PHPz

    PHPz2017-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

    reply
    0
  • PHP中文网

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

    Save the obtained token locally, and just bring it with you every time you request it

    reply
    0
  • PHP中文网

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

    import requests

    r = requests.get(url)

    reply
    0
  • 黄舟

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

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

    reply
    0
  • Cancelreply