+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

无法向端点添加参数

发布于2021-04-12 14:50     阅读(789)     评论(0)     点赞(0)     收藏(4)


0

1

2

3

4

5

6

7

8

大家好,我试图制作一个简单的脚本时遇到了一个错误,我碰到了谷歌的头,但没有找到解决方法。所以问题是,无论何时我运行此代码,我都会从服务器得到一个响应,说“ api密钥丢失”,而不是向我提供我输入的号码的信息,我不知道我是否在做任何错误的顺便说一句。任何帮助,您将不胜感激这是我的代码的示例

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一样)您不需要标头和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: 
---

0

1

2

3

4

5

6

7



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/936024/651ad6e90468877e6496/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)