简体   繁体   English

列表索引必须是整数或切片,而不是 str 为什么会出错

[英]List indices must be integers or slices, not str why the error

I was trying to integrate LoqateAPI for phone number validator, i want to validate bulk phones number in txt files我试图为电话号码验证器集成 LoqateAPI,我想在 txt 文件中验证批量电话号码

BELLOW IS MY CODE波纹管是我的代码

Is anyone here to help me out please, i didn't suppose to get this type of error有人在这里帮助我吗,我没想到会出现这种错误

phone_number = (
    open(
        input(f"\n{bwh}{ble}Enter Phone Number List{res}{gr} [phone.txt]{res} : "), "r"
    )
    .read()
    .splitlines()
)
access_key = input(
    f"\n{bwh}{ble}Enter Your LoqateAPI Key {res}{gr} [AA11-AA11-AA11-AA11]{res} : "
)
country_code = input(f"\n{bwh}{ble}Enter Country Code {res}{gr} [US]{res} : ")
print("------------------------------------------------------------------")
for i in phone_number:
    url = (
        "https://api.addressy.com/PhoneNumberValidation/Interactive/Validate/v2.20/json.ws?&Key="
        + access_key
        + "&Phone="
        + str(i)
        + "&Country="
        + country_code
    )
    response = requests.get(url)
    answer = response.json()
    if answer["carrier"]:

        print(url)
        print(f'{gr}{answer["number"]}{res}{yl} => {cy}{answer["carrier"]}{res}')
        save = open(f'Result/{answer["carrier"]}.txt', "a+")
        save.write(str(i) + "\n")
    else:
        print(f'{red}{answer["number"]} => Die{res}')
        dk = open("Result/die.txt", "a+")
        dk.write(str(i) + "\n")


input("Click Enter For Exit ...!")

This bellow text is my output Below is the problem I'm getting下面的文字是我的 output下面是我遇到的问题

错误图片

** **

Edited I print out the response from a string编辑我从字符串中打印出响应

** **

But the respond was in a json, what type of json is this please i want to know但响应是在 json 中,这是什么类型的 json 请我想知道

Results结果

    [{'PhoneNumber': '+14143392867', 'RequestProcessed': 'True', 'IsValid': 'Yes', 'NetworkCode': '180', 'NetworkName': 'AT&T Wireless', 'NetworkCountry': 'US', 'NationalFormat': '(414) 339-2867', 'CountryPrefix': '1', 'NumberType': 'Mobile'}]
[{'PhoneNumber': '+14146789198', 'RequestProcessed': 'True', 'IsValid': 'Yes', 'NetworkCode': '910', 'NetworkName': 'Google (Grand Central) - SVR', 'NetworkCountry': 'US', 'NationalFormat': '(414) 678-9198', 'CountryPrefix': '1', 'NumberType': 'VOIP'}]
[{'PhoneNumber': '+14148458738', 'RequestProcessed': 'False', 'IsValid': 'Maybe', 'NetworkCode': '', 'NetworkName': '', 'NetworkCountry': 'US', 'NationalFormat': '(414) 845-8738', 'CountryPrefix': '1', 'NumberType': 'Unknown'}]
[{'PhoneNumber': '+14141120704', 'RequestProcessed': 'True', 'IsValid': 'No', 'NetworkCode': '', 'NetworkName': '', 'NetworkCountry': 'US', 'NationalFormat': '(414) 112-0704', 'CountryPrefix': '1', 'NumberType': 'Unknown'}]
[{'PhoneNumber': '+14140646454', 'RequestProcessed': 'True', 'IsValid': 'No', 'NetworkCode': '', 'NetworkName': '', 'NetworkCountry': 'US', 'NationalFormat': '(414) 064-6454', 'CountryPrefix': '1', 'NumberType': 'Unknown'}]
Click Enter For Exit ...!

**I GET IT DONE BY BYPASS OPEN BRACKET "[] IN ARRAY JSON ** **我在阵列 JSON 中通过旁路开括号“[] 完成它 **

Thanks everyone感谢大家

Image1图片1

Image2 图片2

Someone may need help some days too Here is the link of the threads i follow up有些人也可能需要帮助这是我跟进的线程的链接

How To Print Specific value in Array in Python 如何在 Python 中的数组中打印特定值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误列表索引必须是整数或切片,而不是str - error list indices must be integers or slices, not str 列表索引必须是整数或切片,而不是 str 错误 Python - list indices must be integers or slices, not str error Python 我不断收到此错误:列表索引必须是整数或切片,而不是 str - I keep getting this error: list indices must be integers or slices, not str Goodreads API错误:列表索引必须是整数或切片,而不是str - Goodreads API Error: List Indices must be integers or slices, not str Python 错误:列表索引必须是整数或切片,而不是 str - Python Error : list indices must be integers or slices, not str 循环时出现错误“列表索引必须是整数或切片,而不是 str” - Error "list indices must be integers or slices, not str" while looping 类型错误:列表索引必须是整数或切片,而不是 str - Type Error: list indices must be integers or slices, not str TypeError:列表索引必须是整数或切片,而不是str <encoding error> - TypeError: list indices must be integers or slices, not str <encoding error> python json 列表索引必须是整数或切片,而不是 str 错误 - python json list indices must be integers or slices, not str error 在数组中,列表索引必须是整数或切片,而不是 str 错误 python - In an array, list indices must be integers or slices, not str error python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM