Category: Python

Python
2025-05-27 08:55 (11 months ago)
[Outdated] Using Selenium Remote (Selenium Grid) with browser_use

This is sample code for using Selenium Remote Grid in headful mode with `browser_use`. The sample also includes specifying the browser window’s viewport size.

Python
2025-05-21 03:10 (12 months ago)
Obtain HttpOnly=True Session Cookies from Services Logged in via Browser-Use

Pitfalls when passing `--headless` or `-profile` to Selenium Firefox, and the right way to use `selenium.webdriver.FirefoxOptions`.

Python
2025-05-21 02:50 (12 months ago)
Fix: Python 3.13 SSL error 'Basic Constraints of CA cert not marked critical' (VERIFY_X509_STRICT)

Python 3.13 enabled VERIFY_X509_STRICT by default, triggering "SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed: Basic Constraints of CA cert not marked critical" against self-signed CA certs. Workaround: disable VERIFY_X509_STRICT in SSLContext.

Python
2024-07-03 00:23 (22 months ago)
Template Code for Thread Parallelism and Process Parallelism in Python

Expose the Selenium Chromium / ChromeDriver `--remote-debugging-port` (CDP port) outside the container for external clients to connect.

DjangoPython
2024-03-28 00:41 (2 years ago)
The "first" and "second" Arguments of assertEqual in Django's Unit Tests are Actually "expected" and "actual"

When looking at the assertEqual method in Django's unit tests, the first argument is named 'first' and the second argument is named 'second'. It appears that there is no difference in the usage of these variables.

DjangoPython
2024-03-24 04:53 (2 years ago)
Fix: pipenv install fails with AttributeError: module 'pkgutil' has no attribute 'ImpImporter' (Python 3.12)

pipenv install throws "AttributeError: module 'pkgutil' has no attribute 'ImpImporter'" on Python 3.12. Run `python3 -m ensurepip --upgrade` in both the global and virtualenv, or rebuild the pipenv environment.

PythonMicrocontrollers
2023-12-24 09:20 (2 years ago)
Using CircuitPython on the HW-394 ESP-WROOM-32 (ESP32) Development Board

A memo about purchasing a development board featuring the ESP-WROOM-32 module, which appears when searching for "ESP32" on AliExpress, and has "HW-394" written on the board.

PythonRaspberry-Pi
2023-11-21 02:51 (2 years ago)
When Copying Files to Raspberry PI Pico or RP2040 on Mac OS Sonoma Results in Input/Output Error

Here is the solution for resolving Input/output errors or Error code -36 that may occur when trying to copy files to an RP2040 microcontroller board or Raspberry Pi Pico while developing on Mac OS Sonoma.

DjangoPython
2023-11-09 03:39 (2 years ago)
対応方法 When using MySQLdb with Python and encountering "symbol not found in flat namespace '_mysql_affected_rows'"

Fix `symbol not found in flat namespace '_mysql_affected_rows'` when importing MySQLdb in Python — rebuild mysqlclient against the right MySQL client library.

Python
2023-03-29 05:31 (3 years ago)
Trying to Install npm install fibers (node-fibers) Results in ValueError: invalid mode: 'rU' While Trying to Load binding.gyp

Fix `npm install fibers` (node-fibers) failing with `ValueError: invalid mode: 'rU'` — its `setup.py` uses a deprecated flag, so install with Python 3.10 or older.

Python
2023-03-06 07:01 (3 years ago)
Remove 4-byte Characters from Strings in Python

Configure a macOS Service (Quick Action) that copies the absolute path of the file or folder open in Finder to the clipboard.

Python
2023-01-03 02:21 (3 years ago)
Output and Clear Text in Terminal with Python

Flash CircuitPython onto an ESP32 dev board (HW-394 / WROOM-32) and drive I/O in Python — bootloader mode and REPL connection.

Python
2022-12-02 09:02 (3 years ago)
When Using Libraries Like Fabric and Paramiko, "Authentication (publickey) failed." Error Occurs During Server Login

When connecting to an SSH server using Python libraries like Fabric or Paramiko, if the versions are outdated, you may encounter the error "Authentication (publickey) failed."

Python
2022-10-31 12:43 (3 years ago)
A Python Script to Automatically Update ChromeDriver

I wrote a script to download the version of chromedriver that matches the currently installed version of Chrome.

Python
2022-10-09 02:16 (3 years ago)
Code for Creating a Logger When Making Python Command Line Tools

Build an OpenVPN server that routes all clients in a segment through the VPN — from CA cert issuance to distributing `client.ovpn`.

Python
2022-09-19 07:31 (3 years ago)
Fixing the Issue of Separated Voiced Marks in Folder Names on Mac When Outputting from Python

Debug and work around `multipart/form-data` boundary issues during file upload in macOS WebKit (WKWebView / Safari).

Python
2022-09-05 00:49 (3 years ago)
If "pipenv install" Results in RuntimeError: location not created nor specified

Fix `pipenv install` failing with `RuntimeError: location not created nor specified` — remove the venv with `pipenv --rm` and let pipenv recreate it.

DjangoDockerPython
2022-09-03 11:03 (3 years ago)
Changed Django's Docker Environment from Alpine + uWSGI to Debian + Daphne → Ended up with uvicorn After All

Why switch a Django Docker image from Alpine + uWSGI to Debian + Daphne (ASGI), with example Dockerfile and Kubernetes manifest changes.

Python
2022-08-11 15:06 (3 years ago)
Three Workarounds for Failing to Install cryptography When Setting Up a Python Environment in an Alpine Linux Docker Image

Packages required (`apk add ...`) to `pip install cryptography` in an Alpine Linux Docker image, and how to handle common build errors.

Python
2022-04-02 05:32 (4 years ago)
Digital Signage: Python Selenium Script to Launch Chrome in Kiosk Mode

A script to open a website and log in to Google using Python Selenium

Pythonmac
2022-01-03 11:15 (4 years ago)
When pipenv lock Fails on M1 Mac

Fix `pipenv lock` failures on M1 (Apple Silicon) Macs — wheels for `grpcio` / `cryptography` may not exist on arm64, so use Rosetta or pin compatible versions.

Python
2021-11-08 05:52 (4 years ago)
How to Resolve Errors When Installing google-crc32c Version 1.1.3 or Higher on Alpine with Python

When installing `google-crc32c` ≥1.1.3 on Alpine Linux fails to build, work around it by setting CFLAGS to enable SSE4.2 explicitly.

AWSPython
2021-10-15 11:53 (4 years ago)
Resolving UnsupportedProductError in Python ElasticSearch When Using AWS ElasticSearch

Format a USB stick as FAT32 + MBR on a Mac — explicit MBR via `diskutil eraseDisk` arguments.

Python
2021-10-10 09:45 (4 years ago)
Creating and Posting XML with Python

Replace legacy log analyzers (Webalizer / Analog) with GoAccess for Apache / nginx access logs — sample configuration and example output.

Python
2021-06-09 04:24 (4 years ago)
Wait Until the Element Disappears with Puppeteer (Pyppeteer)

Here's an introduction to a code snippet that waits for an element to disappear, using Pyppeteer, which is Python's version of Puppeteer. The same approach should work similarly in Puppeteer's JavaScript version.

Python
2021-03-30 11:44 (5 years ago)
The Specified Version Was Not Installed with Pipenv

Even though the Pipfile specifies ```plaintext [packages] ... Werkzeug = "<1.0.0" ``` running ```plaintext pipenv install --system --skip-lock --dev --deploy ``` installs version 1.0.1.

Python
2021-02-08 14:34 (5 years ago)
If You Can't Install Python Cryptography, Install Rust with rustup

Fix screen redraw issues when Mac Quick Look or Finder content is displayed on a DisplayLink-connected screen.

DjangoMySQLPython
2020-10-11 02:52 (5 years ago)
NameError: name '_mysql' is not defined in Python (Django) (Especially During Local Development)

If a Django project that has been working until now fails to start after a long time with the following error: ``` version_info, _mysql.version_info, _mysql.__file__ NameError: name '_mysql' is not defined ```

Python
2018-10-11 12:31 (7 years ago)
Downloading Files with Requests Using Selenium Webdriver Session Cookies

Pass a logged-in session cookie from Selenium WebDriver into `requests` to download files that require a browser-bound session.

Python
2018-07-04 06:08 (7 years ago)
Reading BOM-Included TSV Files with Python

When you download a CSV from Amazon, it might sometimes be a TSV with a BOM.

Python
2018-06-21 02:34 (7 years ago)
Add SSL CA Certificate to Ubuntu and Use It with Python Requests

1. If the certificate is in DER format, convert it to PEM

Python
2018-02-08 03:10 (8 years ago)
Installing Python 3.5 on Ubuntu 14.04

Building from source is easy

DjangoPython
2017-09-01 02:10 (8 years ago)
What to Do When You Encounter AuthAlreadyAssociated with Django Social Auth

I'm writing this down because I always get flustered.

Python
2017-02-03 00:59 (9 years ago)
Disable geckodriver.log Output in Selenium Firefox

Impersonate a different user during Django debugging by swapping `request.session['_auth_user_id']` to test session-bound logic.

DjangoPython
2016-06-20 08:35 (9 years ago)
Outputting Shift-JIS CSV with Django

How to return a Shift-JIS (CP932) CSV download response from Django on Python 3 — write to StringIO as Unicode first, then encode to cp932 in one shot.

Python
2015-12-01 02:02 (10 years ago)
Retrieve SSL Certificate Expiration Date Using timedelta

Get the SSL certificate expiration period using timedelta

Python
2015-10-19 07:34 (10 years ago)
Write Parallel Processing Easily Using Process Pools

Parallelize CPU-bound Python work with `multiprocessing.Pool` / `ProcessPoolExecutor` — minimal patterns and common pitfalls.

Python
2015-10-16 07:35 (10 years ago)
Python Simple Thread Pool

I should have used multiprocessing.pool.Pool orz

Python
2015-08-11 02:06 (10 years ago)
Running Firefox with Selenium on Headless Linux for Automated Operations in Python

This is a method to launch Selenium from Python on a headless Linux system.

Python
2015-06-17 11:08 (10 years ago)
What to Do When You Can't Import `requests` (_ssl) in Python 3 on a Mac

Fix an `import requests` failure caused by a missing `_ssl` module in Python 3 on macOS — rebuild Python via pyenv so it links against the system OpenSSL.

Python
2015-03-02 10:46 (11 years ago)
Disable Links in docutils' rst Writer (docutils.writers.html4css1)

Couldn't find the configuration item, so I'll use a monkey patch.

Python
2014-03-20 23:30 (12 years ago)
Add Environment Variables When You Encounter the Error "pip install pillow → error: command 'cc' failed with exit status 1"

When running `pip install pillow`, you might encounter the following error:

Python
2014-01-29 10:41 (12 years ago)
A Script to Batch Rename Multiple Files Using an Editor

When you start the program, a list of files is displayed in the editor. You can modify and save the list.

Python
2013-11-18 02:41 (12 years ago)
Comparing Logger Implementations Using Generators and Classes

I wanted to write a logger-like class and wondered, "Which would be more readable, using a generator or a class?" So I wrote and compared both.

Python
2011-12-29 03:04 (14 years ago)
Resolving Readline Errors When Running iPython

When I switched to MacOS Lion and was setting up my environment, I encountered the following error when running iPython:

Python
2011-06-10 17:02 (14 years ago)
Clipboard Input and Output

I'm not very confident about the GTK part

Python
2011-06-09 08:37 (14 years ago)
Using TokyoTyrant as a Model-like TokyoTyrantStorage

# -*- coding: utf-8 -*-

Python
2011-06-07 16:23 (14 years ago)
Convert RFC2822 Date Format to Python's datetime

# -*- coding: utf-8 -*-

Python
2011-06-03 16:34 (14 years ago)
memoized_property

```python

Categories

Archive