发布请求返回404

时间:2017-11-19 16:31:19

标签: python json http-post

最后,我想在过去两天进行高级搜索时“刮”下面的网页。 https://launchstudio.bluetooth.com/Listings/Search

结果似乎是由调用API

的javascript生成的
bt.apiUrl = 'https://platformapi.bluetooth.com/';
$.ajax({
    method: 'post',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    url:  bt.apiUrl +'api/platform/Listings/Search',
    data: JSON.stringify(this.searchCriteria),
    success: function (data) {
        if (data.length) {
            var listings = data
            console.log('listing count: ' + listings.length);
            this.listings = listings;
        }

    }.bind(this)

找到以下API文档: https://platformapi.bluetooth.com/Help/Api/POST-api-Platform-Listings-Search

但是,我的简单脚本返回404

import requests
import json

payload ={
  'UserId': '',
  'MemberId': '',
  'SearchString': '',
  'SearchQualificationsAndDesigns': 1,
  'SearchDeclarationOnly': 1,
  'SearchEndProductList': 1,
  'SearchPRDProductList': 1,
  'SearchMyCompany': 1,
  'BQAApprovalStatusId': 9,
  'BQALockStatusId': 10,
  'ProductTypeId': 1,
  'SpecName': 1,
  'ListingDateEarliest': "2017-11-17T09:43:09.2031162-06:00",
  'ListingDateLatest': "2017-11-18T09:43:09.2031162-06:00",
  'Layers': [],
  'MaxResults': 11,
  'IncludeTestData': 1
}

url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
headers = {'Content-type': 'application/json', 'Accept': 'text/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
print (r.status_code)

任何人都能明白为什么?使用Python 3.5顺便说一句。

1 个答案:

答案 0 :(得分:1)

import requests
import json

payload = {
    "searchString":"bluetooth",
    "searchQualificationsAndDesigns":True,
    "searchDeclarationOnly":True,
    "searchEndProductList":False,
    "searchPRDProductList":True,
    "searchMyCompany":False,
    "productTypeId":0,
    "specName":0,
    "bqaApprovalStatusId":-1,
    "bqaLockStatusId":-1,
    "listingDateEarliest":"",
    "listingDateLatest":"",
    "userId":0,
    "memberId":None,
    "layers":[],
    "maxResults":5000
    }

url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
headers = {'Content-type': 'application/json; charset=utf-8', 'Accept': 'text/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
print (r.status_code)
#print r.json()

结果:

200