??yy 2019-02-25 16:50 采纳率: 0%
浏览 41

在Python中发送ajax标头

One website API require pass as an ajax header to order to setup the connection

.$.ajaxSetup(
{
    headers:
    {
        'API-Key': "<your api key>"
    }
});

I write a Python to simulate this connection,but could only get a response 200:

import sys, socket
import requests

url= 'http://demo.datagearbox.com/api'
access_token ='543d927eecf39069b31cceee60e9d6d1'

result = requests.post(url,
      headers={'Content-Type':'application/json',
               'Authorization': 'API-Key {}'.format(access_token)})

print(result)

Can someone please tell me what I missed? Thank you

  • 写回答

1条回答 默认 最新

  • 零零乙 2019-02-25 16:56
    关注

    Try this:

    result = requests.post(url,
          headers={
              'Content-Type':'application/json', 
              'API-Key': '{}'.format(access_token)
          }
    )
    
    评论

报告相同问题?