我正在尝试通过参考本指南来提取数据。 我有点新。我可以用 api 密钥和 url 提取数据吗?因为我只有 api 密钥和 url。我没有任何其他参数。以下是我尝试过的方法:
import urllib.parse
import urllib.request
url = "https://commerce.campaignmonitor.com/api/v1/abandoned-carts/campaigns"
header={"x-api-key" : 'my_api_key'}
post_param = urllib.parse.urlencode({
'user' : 'i_dont_know',
'status-update' : 'i_dont_know'
}).encode('UTF-8')
req = urllib.request.Request(url, post_param, header)
response = urllib.request.urlopen(req)
还有这个:
from requests.auth import HTTPBasicAuth
import requests
import urllib
url ="https://commerce.campaignmonitor.com/api/v1/abandoned-carts/campaigns"
headers = {"Accept": "application/json"}
auth = HTTPBasicAuth('my_api_key', 'i_dont_know')
req = requests.get(url, headers=headers , auth=auth)
response = urllib.request.urlopen(req)
但我有错误:
AttributeError: 'Response' object has no attribute 'type'
在其他方法中,我得到 401 错误