I'm new to python. I'm trying to get a web page using urllib. This is working on normal class. I want to cleanup the code so I usually put them to static method and call them in other class.
When the code executed, the program immediately stops and no error codes in the console. If I don't use the decode function, there is no error but the data is in bytes.
Can someone enlighten me why this happen?
import sys
import urllib.request
class AppTool():
@staticmethod
def getURL(URL):
result = ""
try:
request = urllib.request.Request(URL)
response = urllib.request.urlopen(request)
result = response.read().decode('utf-8')
print("result : {}".format(result))
except:
print("Error: {}".format(sys.exc_info()))
return result