如何使用我的输入数据调用API URI

时间:2017-06-07 09:37:22

标签: python api url

为了进行地理编码,我试图从pitney bowes获取客户信息API,因为他们提供了以下详细信息。

给出:

POST https://api.pitneybowes.com/identify/identifyaddress/v1/rest/validatemailingaddress/results.json HTTP/1.1

    Content-Type: application/json
    Authorization: Bearer {YOUR ACCESS TOKEN}
    Host: api.pitneybowes.com
    {
      "options": {
        "OutputCasing": "M"
      },
      "Input": {
        "Row": [
          {
            "AddressLine1": "",
            "AddressLine2": "",
            "City": "",
            "Country": "",
            "StateProvince": "",
            "PostalCode": "",
            "FirmName": ""
          }
        ]
      }
    }

我的节目得到了回应405。为什么我会在发送帖子请求时获得<Response [405]>

我的节目是:

import requests
url = 
 'https://api.pitneybowes.com/identify/identifyaddress/v1/rest/validatemailingaddress/results.json HTTP/1.1'
data = '''{
"options": {
    "OutputCasing": "M"
    },
"Input":
    {
    "Row": [
        {
            "AddressLine1": "line1",
            "AddressLine2": "line2",
            "City": "xxx",
            "Country": "yyy",
            "StateProvince": "aaa",
            "PostalCode": "xxx",
            "FirmName": ""
            }
        ]
     }
    }'''
headers={'Content-Type': 'application/json',
                              'Authorization': 'Bearer 
{nGdl0cndcnYN0FK6gmeFQ6CXRYO9}'}
response = requests.post( url, data=data,
                     headers=headers)
print response

1 个答案:

答案 0 :(得分:0)

IdentifyAddress API标准化并验证地址,您应使用Geocode API进行地理编码。

这是调用Identify Address API的正确python代码,希望这会有所帮助:

import requests
url = 'https://api.pitneybowes.com/identify/identifyaddress/v1/rest/validatemailingaddress/results.json'
data = '''{
"options": {
    "OutputCasing": "M"
    },
"Input":
    {
    "Row": [
        {
            "AddressLine1": "4750 Walnut St",
            "AddressLine2": "",
            "City": "Boulder",
            "Country": "USA",
            "StateProvince": "CO",
            "PostalCode": "80301",
            "FirmName": "Pitney Bowes Software"
            }
        ]
     }
    }'''
headers={'Content-Type': 'application/json','Authorization': 'Bearer YImXVIfpDOsadpv8SCohGAC0ALcO'}
response = requests.post( url, data=data, headers=headers)
print response.text