Problema:
Ao tentar fazer urlsplit de uma URL em 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).pathvocê vê a seguinte mensagem de erro:
urlsplit_attributeerror.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'Solução
O equivalente de urlparse.urlsplit() em Python 3 é urllib.parse.urlsplit().
Portanto, um exemplo de código funcionando é
urlsplit_fix_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).path
Check 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