Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python错误:AttributeError:';str';对象没有属性';阅读';_Python_Json_Python 3.x_Python Requests - Fatal编程技术网

Python错误:AttributeError:';str';对象没有属性';阅读';

Python错误:AttributeError:';str';对象没有属性';阅读';,python,json,python-3.x,python-requests,Python,Json,Python 3.x,Python Requests,我的完整代码: import requests as req import json Bin = int(300000) BinMax = int(600000) File = open("C:/Users/admin/Desktop/PS Now Generaetors/Bins.txt", 'a') while bin != BinMax: json1 = req.get("https://lookup.binlist.net/" + str(Bin)) json2 = j

我的完整代码:

import requests as req
import json
Bin = int(300000)
BinMax = int(600000)
File = open("C:/Users/admin/Desktop/PS Now Generaetors/Bins.txt", 'a')

while bin != BinMax:
    json1 = req.get("https://lookup.binlist.net/" + str(Bin))
    json2 = json1.text
    jsonout = json.load(json2)
    country = jsonout["country"]
    cc = country["alpha2"]
    if cc == "US" or "AT" or "BE" or "CA" or "FR" or "De" or "IE" or "JP" or "LU" or "NL" or "CH" or "GB" or "ES" or "IT" or "PT" or "NO" or "DK" or "FI" or "SE" or "PH":
        print (bin, "writed")
        File.write("\n" + str(Bin) + ";" + cc)
    bin =+ 1
完全错误:

Traceback (most recent call last):
  File "C:\Users\admin\Desktop\PS Now Generaetors\Bin generator.py", line 10, in <module>
    jsonout = json.load(json2)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'
回溯(最近一次呼叫最后一次):
文件“C:\Users\admin\Desktop\PS Now Generators\Bin generator.py”,第10行,在
jsonout=json.load(json2)
文件“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64_uuuQBZ5N2KFRA8P0\lib\json\\uuuuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
返回加载(fp.read(),
AttributeError:“str”对象没有属性“read”
如何修复它?

您必须使用

json.loads(json2)
而不是“加载”

看更多

文件似乎包含字符串,而不是JSON对象。如果您使用请求并想要JSON,则可以执行
jsonout=json1.JSON()
而不是获取文本,然后使用
JSON.loads()