How to fix Python 3 AttributeError: 'function' object has no attribute 'urlsplit'
Problem:
When trying to urlsplit an URL in Python 3:
urlsplit_misuse_example.py
from urllib.parse import urlparse
path = urlparse.urlsplit(remote_image_url).pathurlsplit_misuse_example.py
from urllib.parse import urlparse
path = urlparse.urlsplit(remote_image_url).pathyou see the following error message:
example.txt
AttributeError Traceback (most recent call last)
Input In [30], in <cell line: 3>()
1 from urllib.parse import urlparse
----> 3 path = urlparse.urlsplit(remote_image_url).path
4 filename = posixpath.basename(path)
AttributeError: 'function' object has no attribute 'urlsplit'traceback.txt
AttributeError Traceback (most recent call last)
Input In [30], in <cell line: 3>()
1 from urllib.parse import urlparse
----> 3 path = urlparse.urlsplit(remote_image_url).path
4 filename = posixpath.basename(path)
AttributeError: 'function' object has no attribute 'urlsplit'Solution
The equivalent of urlparse.urlsplit() in Python 3 is urllib.parse.urlsplit().
Therefore, a working code example is
example.py
from urllib.parse import urlsplit
path = urlsplit(remote_image_url).pathurlsplit_fix_example.py
from urllib.parse import urlsplit
path = urlsplit(remote_image_url).pathCheck out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow