There is an error with the website where you got those lines of code for your first attempt (I have seen that same error)
The line in error is
nltk.set_proxy('http://proxy.example.com:3128' ('USERNAME', 'PASSWORD'))
You need a comma to separate the arguments. The correct line should be
nltk.set_proxy('http://proxy.example.com:3128', ('USERNAME', 'PASSWORD'))
This will work just fine.