Handle URLs passed with %xx escape.

E.g.: "https://linuxreference.wordpress.com/2010/12/28/25-even-more-%E2%80%93-sick-linux-commands/"
This commit is contained in:
Arun Prakash Jana 2016-04-09 14:52:31 +05:30
parent b499daade4
commit 4c25e0b1c0
No known key found for this signature in database
GPG Key ID: C0A712ED95043DCB

8
buku
View File

@ -25,7 +25,7 @@ import readline
import webbrowser import webbrowser
import html.parser as HTMLParser import html.parser as HTMLParser
from http.client import HTTPConnection, HTTPSConnection from http.client import HTTPConnection, HTTPSConnection
from urllib.parse import urljoin, unquote from urllib.parse import urljoin, quote, unquote
import signal import signal
import shutil import shutil
@ -214,6 +214,12 @@ def getPageResp(url, redir=False):
print("server: [%s]" % server) print("server: [%s]" % server)
print("URL: [%s]" % url) print("URL: [%s]" % url)
# Handle URLs passed with %xx escape
try:
url.encode('ascii')
except:
url = quote(url)
urlconn.request("GET", url) urlconn.request("GET", url)
resp = urlconn.getresponse() resp = urlconn.getresponse()
return (urlconn, resp) return (urlconn, resp)