Adding python logging to FastApi endpoints, hosted on docker doesn’t display API Endpoints logs

Inspired by JPG’s answer, but using a pydantic model looked cleaner. You might want to expose more variables. This config worked good for me. from pydantic import BaseModel class LogConfig(BaseModel): “””Logging configuration to be set for the server””” LOGGER_NAME: str = “mycoolapp” LOG_FORMAT: str = “%(levelprefix)s | %(asctime)s | %(message)s” LOG_LEVEL: str = “DEBUG” # … Read more

Attempting to resolve blurred tkinter text + scaling on Windows 10 high DPI displays, but concerned my approach is not Pythonic or is unsafe

Simply using from ctypes import windll windll.shcore.SetProcessDpiAwareness(1) and allowing font size adjustment solved my problems on Windows 10. Not sure why no one commented or assisted though. The blurry fonts are a pain, I would expect this thread had a debate and a best solution for this Tkinter nuisance..

Specific type annotation for NumPy ndarray using mypy

What you are looking for is the numpy.typing.NDArray class: https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray numpy.typing.NDArray[A] is an alias for numpy.ndarray[Any, numpy.dtype[A]]: import numpy as np import numpy.typing as npt a: npt.NDArray[np.complex64] = np.zeros((3, 3), dtype=np.complex64) # reveal_type(a) # -> numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]]] print(a) prints [[0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j]] Note that even though you annotate … Read more

Mock exception raised in function using Pytest

You can mock error raising via side_effect parameter: Alternatively side_effect can be an exception class or instance. In this case the exception will be raised when the mock is called. In your case, this can be used like this (assuming call_api is defined in module foo): import pytest from unittest.mock import patch def test_api(): with … Read more

TypeError: WebDriver.__init__() got an unexpected keyword argument ‘executable_path’ in Selenium Python

This is due to changes in selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e Note that executable_path was removed. If you want to pass in an executable_path, you’ll have to use the service arg now. from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service(executable_path=”./chromedriver.exe”) options = webdriver.ChromeOptions() driver = webdriver.Chrome(service=service, options=options) # … driver.quit()

Python 3.2: How to pass a dictionary into str.format()

This does the job: stats = { ‘copied’: 5, ‘skipped’: 14 } print( ‘Copied: {copied}, Skipped: {skipped}’.format( **stats ) ) #use ** to “unpack” a dictionary For more info please refer to: http://docs.python.org/py3k/library/string.html#format-examples and http://docs.python.org/py3k/tutorial/controlflow.html#keyword-arguments

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)