getting this error 'AttributeError: 'str' object has no attribute 'get_balance_f' on my rest api
Im making a rest api so I can communicate with my python script that does requests to a website and gets the data from the website.
class Classroom():
def __init__(self, numbercard, password) -> None:
self.session = requests.Session()
self.school = 400786
self.numbercard = numbercard
self.password = password
self.logged_in = False
def login(self):
payload = {
'modo': 'manual',
'escola': '400786',
'nrcartao': self.numbercard,
'codigo': self.password,
}
res = self.session.post('http://giae.esars.pt/cgi-bin/webgiae2.exe/loginv2',
json=payload)
self.logged_in = res.ok
def get_balance_f(self):
balance_request = self.session.get('http://giae.esars.pt/cgi-
bin/webgiae2.exe/saldo')
balance_json = balance_request.json()
self.balance = balance_json['saldo']
print(balance_json['saldo'])
this is one part of my python scrip that logins into the website and gets how much money i have in my school card.
from flask import Flask, request
from classroom import Classroom
from random import choice
chars = [
'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
'o',
'p',
'a',
's',
'd',
'f',
'g',
'h',
'j',
'k',
]
app = Flask(__name__)
def generate_id() -> str:
return ''.join(choice(chars) for _ in range(8))
@app.route('/login', methods = ['POST', 'GET'])
def login_receive():
card_number = request.json['username']
password = request.json['password']
user = Classroom(card_number, password)
user.login()
if user.logged_in:
uid = generate_id()
return {'message': 'Login succesful', 'uid':uid}
else:
return {'message': 'Login failed'}
@app.route('/classroom/myinfo', methods=['GET', 'POST'])
def myinfo():
user = request.headers['uid']
return user.get_balance_f()
on this code the login part is working, but when i tried to send a get request i get this error 'AttributeError: 'str' object has no attribute 'get_balance_f', and i dont get it.
Comments
Post a Comment