Python FullContact API类型

2024-06-01 09:41:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是fullcontact person enrich API,但运行该程序时出现以下错误:

'TypeError:POST数据应为字节、字节的iterable或文件对象。它不能是str类型

我已经尝试过对数据进行编码,但还没有找到确切的方法。见下面的代码:

import urllib.request
import json

req = urllib.request.Request('https://api.fullcontact.com/v3/person.enrich')
req.add_header('Authorization', 'Bearer {your api key}')

data = json.dumps({
  "emails": [
    "example@fullcontact.com"
  ]
})

response = urllib.request.urlopen(req,data)

Tags: 数据import程序comapijsondata字节