If you are running Python 2.6 then there isn't any "request" in "urllib". So the third line becomes:
m = urllib.urlopen(url)
And in version 3 you should use this:
links = linkregex.findall(str(msg))
Because 'msg' is a bytes object and not a string as findall() expects. Or you could decode using the correct encoding. For instance, if "latin1" is the encoding then:
links = linkregex.findall(msg.decode("latin1"))