Skip to content

Instantly share code, notes, and snippets.

@worldmind
Last active September 25, 2019 14:11
Show Gist options
  • Save worldmind/00d8c37f8a4d466ccbb7be0d44a71db2 to your computer and use it in GitHub Desktop.
Save worldmind/00d8c37f8a4d466ccbb7be0d44a71db2 to your computer and use it in GitHub Desktop.
Python Url type
from urllib.parse import quote, urlencode, ParseResult as Url
Url.__str__ = Url.geturl
bucket_name = 'something_with space'
file_name = 'data.txt'
url = Url(
scheme='https',
netloc='s3.console.aws.amazon.com',
path=quote(f"/s3/buckets/{bucket_name}/{file_name}"),
params='',
query=urlencode({'region': 'Беларусь'}),
fragment='',
)
print(url)
@worldmind
Copy link
Author

 $ python3 url.py                                                                                                                            
https://s3.console.aws.amazon.com/s3/buckets/something_with%20space/data.txt?region=%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D1%8C

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