diff --git a/perma_web/api/views.py b/perma_web/api/views.py index 01dadbc66..2891eba76 100644 --- a/perma_web/api/views.py +++ b/perma_web/api/views.py @@ -511,7 +511,7 @@ def post(self, request, format=None): role='primary', status='pending', record_type='response', - url=link.submitted_url, + url=link.ascii_safe_url, ).save() # create screenshot placeholder diff --git a/perma_web/perma/models.py b/perma_web/perma/models.py index ab04000a6..99519d0be 100755 --- a/perma_web/perma/models.py +++ b/perma_web/perma/models.py @@ -1599,8 +1599,16 @@ def ia_identifier(self): @cached_property def ascii_safe_url(self): - """ Encoded URL as string rather than unicode. """ - return requests.utils.requote_uri(self.submitted_url) + """URL as encoded internally by python requests""" + try: + # Attempt to quote the URL as well as possible: + # - percent encoding + # - unicode domains to punycode + # - etc. + return requests.Request('GET', self.submitted_url).prepare().url + except requests.exceptions.RequestException: + # If that fails, just percent encode everything for safety + return requests.utils.requote_uri(self.submitted_url) @cached_property def url_details(self):