Urgent.News

What's breaking now, across thousands of outlets.

Tech

48-Hour Field Notes: I Printed the Preferred Encoding. That Was Not the Open Default.

I spent the first evening sure the patch was finished, because the sample opened and the assertion printed the name I expected. Have you ever watched a text-mode read succeed on your laptop and then die the moment a clean job starts? I had a short traceback, a green local run, and a bad guess that the suggested edit had covered the real open. The bytes were valid UTF-8, so why did the clean job…

The writer spent an evening convinced their patch was complete since the sample opened and the assertion printed the expected name. However, a traceback appeared when a clean job started. The bytes were valid UTF-8, yet the clean job mentioned an ASCII codec. The writer examined the diff, ran pytest, and reran the test, but the issue persisted.

After checking the sample bytes and confirming they were UTF-8 without a BOM, the writer ran the pytest in the editor terminal and a fresh local shell, both times with green results. They then copied the job command onto their laptop without the job environment, which masked the real difference for another hour. The writer then requested another rewrite, submitting only the failing assertion, which received a new expected string that didn't mention locale.

The writer realized they had pasted the wrong world and needed to include the locale and interpreter flags in their paste. The writer's understanding deepened when they ran the test in a shell closer to a fresh image, exporting LANG and LC_ALL as C. After printing every encoding helper the standard library was willing to show, the writer discovered that Python text mode doesn't mean UTF-8 on every machine.

The implicit open consults a potentially ASCII-compatible encoding, while a non-ASCII name raises an exception instead of returning a string. A suggested solution was to trust the preferred encoding, but the writer emphasized the importance of checking which helper open actually consults before blindly following advice. The writer concluded that PEP 540 describes UTF-8 mode, but it doesn't guarantee a fix for Path.read_text on every release.

The writer highlighted the importance of using locale.getpreferredencoding(False) and locale.getencoding() for a more accurate understanding of the locale encoding. The writer cautioned against relying solely on the print statement and emphasized the need to review the open() and locale documentation for the specific interpreter version.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

My jobs search API returned the same posting five times — syndication broke my URL dedup

I run a Job Postings Search API ( https://x402.freeq.one/tools/jobs.html ) that queries live postings across boards and returns structured results — title, company, location, apply URL, salary…

  • API fetches job listings from multiple boards, returns 240 total, 178 unique
  • Same posting appears five times due to syndication, tracking mechanisms
  • Three-layer normalization process successfully reduces duplicates by 25%

Hyper3D Rodin 3D Review 2026: The Foil Folds Turn Into a Mask

Independent review. I ran both tools on my own accounts, free and paid, with no vendor-provided access or early access of any kind.

  • Hyper3D Rodin 3D reviewed on crumpled foil image
  • SupaVoxel preserves varied ridges better than Hyper3D
  • Hyper3D creates near-mirrored mask, SupaVoxel keeps irregular ridges

More from Friday 9 October →