Python error: AttributeError: str object has no attribute read

2024/11/18 16:39:18

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.textjsonout = 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 loadreturn loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'

How to fix it?

Answer

You have to use

json.loads(json2)

instead of "load".

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

https://en.xdnf.cn/q/120054.html

Related Q&A

list elements sum of one list first element to last element of second list

How to sum first element of one list to last element of second list if both list contains same amount of elements in python. Source code (should be kind of like this): def update(l1,l2,l3):for i in ran…

Append float data at the end of each line in a text file

I have a .txt file and Im trying to add float number at the end of each line with incremented value than the last line. This is what I have in the .txt file:>520.980000 172.900000 357.440000 >320…

Change and Sort list in list in specific order in python

Hello guys I have this type of data in list in list array = [ ["PRODUCT NAME PACK","BAIGAM KOT","FIAZ BAGH","OLD ANARKALI","SULTAN PURA","TEZAB AA…

How to interact with the reCAPTCHA Solve the challenge button using Selenium and Python

Im trying to interact with the recaptcha Solve the challenge button on image verification popup using Selenium and Python. The xpath looks correct in dev tools but using Selenium unable to interact wit…

How to convert an adjacency matrix to an adjacency list with python?

I have an adjacency matrix like: [[ 0., 15., 0., 7., 10., 0.],[ 15., 0., 9., 11., 0., 9.],[ 0., 9., 0., 0., 12., 7.],[ 7., 11., 0., 0., 8., 14.],[ 10., 0., 12., …

how to plot a box plot of a column of a data frame in two groups in matplotlib

I have the following data frame:value total_spend margin1 29493.14 10203.371 27551.22 19003.072 22881.26 15142.681 15254.77 12337.221 11873.95 9424.231 11382.89 8767.83…

Text manipulation to form an equation

a=0.77 ,b=0.2 ,c=0.20, d=0.79 ,z=(c+d), e=(z*a) ,output=(z+e) I have a text file like above. I need a parser logic that will throw an equation like output=(0.20+0.79)+((0.20+0.79)*a) what are some effi…

Python If statement and logical operator issue [duplicate]

This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 6 years ago.Im trying to create a small python program to emulate rolling a…

How do I replace a specific string in a 2d array?

Im making a program that Identifies if a blank tile exists or not. I already have a code in my 2d array which is arr2 = [[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0…

from _dlib_pybind11 import * ModuleNotFoundError: No module named _dlib_pybind11

I actually working on a face recognition project but getting an error such as: from _dlib_pybind11 import * ModuleNotFoundError: No module named _dlib_pybind11Please help Ill appreciate any bits of hel…