-1

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.loads(json2)
    country = jsonout["country"]
    cc = country["alpha2"]
    if "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" == cc:
        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\test.py", line 3, in <module>
    json2 = json1.read()
AttributeError: 'Response' object has no attribute 'read'

How to fix it? Please help.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
farkon00
  • 109
  • 1
  • 8
  • 2
    `json2 = json1.read()` That line is not in the posted code sample. Please edit the question to include your actual code. – John Gordon Jun 09 '20 at 16:58
  • Josh Gordon, its full code and every string in question. I too dont understand why error have string ```json2 = json1.read()``` – farkon00 Jun 09 '20 at 17:02
  • 1
    Your posted code has `json2 = json1.text`, not `json2 = json1.read()`. Also, the error message says it's on line 3, which does not match the posted code. We can't help if you don't show us the real code you're using. – John Gordon Jun 09 '20 at 17:04

1 Answers1

1
  1. Use .json() to convert response to python dict. There's no need in import json usage.
  2. Your country code comparison is invalid.

Try to do something like this:

import requests

Bin = 300000  # no need for int()
BinMax = 600000  # no need for int()
File = open("C:/Users/admin/Desktop/PS Now Generaetors/Bins.txt", 'a')
countries = ("US", "AT", "BE", "CA", "FR", "De", "IE", "JP", "LU", "NL", "CH", "GB", "ES", "IT", "PT", "NO", "DK", "FI", "SE", "PH")

while Bin != BinMax:
    response = requests.get("https://lookup.binlist.net/" + str(Bin))
    jsonout = response.json()  # use .json() to get response as JSON
    country = jsonout["country"]
    cc = country["alpha2"]
    if cc in countries:  # previous comparison won't work as you expect
        print(bin, "written")
        File.write("\n" + str(Bin) + ";" + cc)
    Bin =+ 1
Ivan Vinogradov
  • 4,269
  • 6
  • 29
  • 39