[1.7.x] Fixed #23909 -- Prevented crash when collecting SQL for RunSQL

Thanks James Rivett-Carnac for the report and Markus Holtermann
for the review.
Backport of e11c6fd21 from master.
[1.7.x] Fixed #23934 -- Fixed regression in admin views obj parameter.

Backport of 0623f4dea46eefba46efde6c6528f7d813ef4391 from master
[1.7.x] Fixed #23946 -- Fixed runserver crash when socket error contains Unicode chars.

Backport of bba545345f46f09245799f7ae0a22177a84eba71 from master
[1.7.x] Tweaked fix for refs #23946; thanks Claude.

Backport of 5c773447c3239a297b22929f0df15d2971d72e77 from master
[1.7.x] Added some directories on Jenkins to flake8 exclude.

Backport of 53908c1f934b32e83e9fa34c14910b1837f7f610 from master