Skip to content

Conversation

@martinpitt
Copy link
Contributor

@martinpitt martinpitt commented Apr 11, 2025

get_metadata_from_url() previousl fell back to urllib.urlopen() on HTTPErrors, due to its overly wide except (never catch Exception!), which leads to unnecessarily long and confusing backtraces.

Other places did not have a Python 2 fallback at all. Directly import the urlopen function from the respective module to simplify the code.

Also drop the unused urllib.parse import.


Spotted in linux-system-roles/firewall#258 in this run

Tested with sudo pip install ~/upstream/lsr/tox-lsr and running firewall qemu tox tests locally.

`get_metadata_from_url()` previousl fell back to urllib.urlopen() on
HTTPErrors, due to its overly wide `except` (never catch `Exception`!),
which leads to unnecessarily long and confusing backtraces.

Other places did not have a Python 2 fallback at all. Directly import
the `urlopen` function from the respective module to simplify the code.

Also drop the unused `urllib.parse` import.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/tox_lsr/test_scripts/runqemu.py:152

  • In Python 2, the object returned by urlopen may not support the context manager protocol. Consider implementing a wrapper or using a try/finally block to ensure proper resource cleanup when running in Python 2.
with urlopen(url) as url_response:  # nosec

@richm richm merged commit c7e64ed into linux-system-roles:main Apr 11, 2025
7 checks passed
@martinpitt martinpitt deleted the fix-urlopen branch April 11, 2025 14:46
@martinpitt
Copy link
Contributor Author

another instance from today. Makes me think we should intercept that error and retry a few times with exponential back-off.

@richm
Copy link
Contributor

richm commented Apr 14, 2025

another instance from today. Makes me think we should intercept that error and retry a few times with exponential back-off.

Yes, sounds good.

@martinpitt
Copy link
Contributor Author

Done in #185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants