]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(robots): Process redirect with non-encoded URL
authorOleg Broytman <phd@phdru.name>
Sun, 12 Nov 2023 18:56:15 +0000 (21:56 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 13 Nov 2023 19:02:26 +0000 (22:02 +0300)
Robots/bkmk_robot_base.py

index b5cac691fe9f2842d12184f30de6c6b2271dbb83..85c704a64955608c5add79747020d2b48ea74889 100644 (file)
@@ -274,8 +274,15 @@ class robot_base(Robot):
         return 1
 
     def set_redirect(self, bookmark, errcode, newurl):
-        bookmark.moved = "(%s) to %s" % (reloc_dict[errcode], newurl)
-        self.log('   Moved: %s' % bookmark.moved)
+        bookmark.moved = moved = "(%s) to %s" % (reloc_dict[errcode], newurl)
+        try:
+            moved.encode('ascii')
+        except UnicodeEncodeError:
+            try:
+                moved = moved.encode(bookmark.charset)
+            except (LookupError, TypeError, UnicodeEncodeError):
+                moved = moved.encode('utf-8')
+        self.log('   Moved: %s' % moved)
 
     def finish_check_url(self, bookmark):
         start = self.start