Category : python

I am new to pytest and working on to test the code. How ever the test result showing failed. **main.py** @app.post("/loginsuccess/", response_class=HTMLResponse) async def login_success(request: Request, username: str = Form(…), password: str = Form(…)): p = await User_Pydantic.from_tortoise_orm(await User.get(username=username, password=password)) json_compatible_item_data = jsonable_encoder(p) if json_compatible_item_data is not None: logger.info("Logged in Successfully") return templates.TemplateResponse("homepage.html", {"request": request, ..

Read more

I am new to the above module and trying to figure out how to use it. I am working through a corporate NTLM proxy server in order to connect to an external API. Previously I would just use the proxy option within python-requests for such tasks. So far I have followed the instructions at https://github.com/genotrance/px ..

Read more

In order to detect a fault that would happen in my cron job, I set an other cron job to check the previous log issued by the crontab: def check_last_cron(): with open(‘/home/pi/Desktop/cron_output.log’) as f: txt = f.read() f.close() if ‘Traceback’ in txt: print(‘Traceback detected’) send_to_phone(txt) else: print(‘no Traceback detected’) When run manually, everything goes well: ..

Read more

My code : class parent(object): @property def value(self): return self.val class child(parent): #__init__ @parent.value.setter def value(self): return self.get_val() This code is not setting the property value to self.get_val() , instead it is using the old value that is set in the parent. Here , the parent class has no specific setter method but I need ..

Read more

I have two large files (sets of filenames). Roughly 30.000 lines in each file. I am trying to find a fast way of finding lines in file1 that are not present in file2. For example, if this is file1: A=1 B=2 C=3 And this is file2: A=10 B=20 C=30 D=5 Then my result/output should be: ..

Read more

I keep getting this error: Replacement index 1 out of range for positional args tuple on this line of code: print("'{1}’, ‘{2}’, ‘{3}’, ‘{4}’".format(question[3]), question[4], question[5], question[6]) here is my full code def quiz(userID,topicID): with sqlite3.connect("Quiz.db") as db: cursor = db.cursor() score = 0 cursor.execute("SELECT * FROM questions WHERE topicID=?",[(topicID)]) questions = cursor.fetchall() numOfQuestions = ..

Read more

I have a problem. I want to delete row from mysql table. I don’t understand what is wrong. Application return error only production linux enviroment, on Windows everything is okay. def sql_execute(conn, sql, val): try: cursor = conn.cursor() cursor.execute(sql, val) conn.commit() except mysql.connector.Error as e: print("sql_insert: ", info.error_insert_info, e) def delete_type_for_id(conn, val): sql = "DELETE ..

Read more

I have events represented like this: event = { "properties": { "http.requestMethod": "POST", "http.userAgent": "wget", "device.product": "ASA", "device.vendor": "Cisco" } } I would like to represent and validate these events using pydantic, but I am required to split all of the different namespaces into their own classes like this: from pydantic import BaseModel, Field class ..

Read more

I am trying to learn how python handles multiprocessing and have followed a youtube tutorial for some basic code but I am now trying to implement a ProcessPoolExecuter myself. I have the following code which is causing the problem: with concurrent.futures.ProcessPoolExecutor() as executor: results = executor.map(func, sets, repeat(testNumbers)) for result in results: print(result) where the ..

Read more