无法将参数添加到端点

Failure to add params to endpoint

大家好,我在尝试制作一个简单的脚本时遇到了一个错误,我和 google 都摸不着头脑,但没有找到解决方案。所以问题是任何时候我 运行 我得到这个代码 服务器的响应说“缺少 api-key”,而不是给我输入的号码信息,顺便说一句,我不知道我是否做错了什么。任何帮助你将不胜感激 这是我的代码示例

import requests
list = input('Input Phone Numbers List :')
link = "http://apilayer.net/api/validate"
head = {'User-agent': 'user-agent-here'}
s = requests.session()
session = s.get(link,headers=head)
phone = open(list, 'r')
while True:
    num = phone.readline().replace('\n', '')
    if not num:
        break
    cot = num.strip().split(':')
    send = s.post(link,
    data={'access_key':'1135810505585d6e034f640fbf30a700','number':cot[0]},headers=head,)
    (stats, respond) = (send.status_code, send.text)
    print (stats, respond)

numverify.com 上的示例表明它需要 GET 请求,因此它需要 get(..., params=...) 的值,但在开始时(在 while True 之前)您使用 get()没有任何参数 - 这会产生问题。

您不需要 post() 并且(与大多数 API 一样)您不需要 headers 和 cookie。

import requests

#list = input('Input Phone Numbers List :')

link = "http://apilayer.net/api/validate"

payload = {
    'access_key': '1135810505585d6e034f640fbf30a700',
    'number': '',
}

#phone = open(list, 'r')
phone = ['+14158586273', '+46123456789']

for num in phone:
    num = num.strip()
    if num:
        cot = num.split(':')
        
        payload['number'] = cot[0]
        
        response = requests.get(link, params=payload)
        
        print('status:', response.status_code)
        print('text:', response.text)
        print('---')
        
        data = response.json()
        
        print('number:', data['international_format'])
        print('country:', data['country_name'])
        print('location:', data['location'])
        print('carrier:', data['carrier'])
        print('---')
        
        
        

结果:

status: 200
text: {"valid":true,"number":"14158586273","local_format":"4158586273","international_format":"+14158586273","country_prefix":"+1","country_code":"US","country_name":"United States of America","location":"Novato","carrier":"AT&T Mobility LLC","line_type":"mobile"}
---
number: +14158586273
country: United States of America
location: Novato
carrier: AT&T Mobility LLC
---
status: 200
text: {"valid":true,"number":"46123456789","local_format":"0123456789","international_format":"+46123456789","country_prefix":"+46","country_code":"SE","country_name":"Sweden","location":"Valdemarsvik","carrier":"","line_type":"landline"}
---
number: +46123456789
country: Sweden
location: Valdemarsvik
carrier: 
---