-2

My full code:

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

Full Error:

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'

How to fix it?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
farkon00
  • 109
  • 1
  • 8
  • 1
    It looks like your file contains a string, not a JSON object. – lolu Jun 09 '20 at 15:18
  • 3
    Your `if` statement [is wrong](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – Cory Kramer Jun 09 '20 at 15:19
  • 1
    if youre using requests and you want json you can just do `jsonout = json1.json()` instead of getting text and then using `json.loads()` – Craicerjack Jun 09 '20 at 15:21

1 Answers1

2

You have to use

json.loads(json2)

instead of "load".

See more https://www.w3schools.com/python/python_json.asp

Vanillaboy
  • 388
  • 1
  • 11