You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
googleapiclient modules use urllib.parse but only import urllib, crashing when urllib.parse was not imported elsewhere #2803
File ".../googleapiclient/_helpers.py", line 183, in _update_query_params
parts = urllib.parse.urlparse(uri)
^^^^^^^^^^^^
AttributeError: module 'urllib' has no attribute 'parse'
Root cause
Four modules import the bare urllib package but call urllib.parse.* functions:
module
urllib.parse call sites
googleapiclient/_helpers.py
4
googleapiclient/discovery.py
6
googleapiclient/http.py
6
googleapiclient/model.py
1
In Python, import urllib does not import its submodules; urllib.parse only becomes accessible as an attribute of the package after some module somewhere executes import urllib.parse (or from urllib.parse import ...). The library currently works only because httplib2, imported transitively by discovery.py/http.py/model.py, happens to register urllib.parse first. _helpers.py imports nothing but the standard library, so using it before anything has imported urllib.parse crashes as above.
Visible symptom in this repository's own test suite
pytest tests/test__helpers.py
# 7 failed, 3 passed — every failure is AttributeError: module 'urllib' has no attribute 'parse'
The same tests pass in a full-suite run because other test modules import urllib.parse first — the same accidental-transitive-import mechanism.
Proposed fix
Replace import urllib with import urllib.parse in the four modules listed above. Call sites keep their current urllib.parse.urlparse(...) spelling, so the change is one line per module. This removes the undeclared dependency on third-party import side effects for all four modules, not just the one that currently crashes.
Activity
fix: import urllib.parse explicitly instead of relying on side effects (