簡體   English   中英

如何使用我的輸入數據調用API URI

[英]How to call API URI with my input data

為了進行地理編碼,我嘗試從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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM