Python Forum

Full Version: authentication required error with urlopen
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Everyone,
I'm trying following code, but ending up Authentication Required Error. I'm able to browse the website from browser without any credentials, but not through python script. How can I mitigate this error? Any Help please?

from urllib.request import urlopen
with urlopen('http://sixty-north.com/c/t.txt') as story:
    story_words = []
    for line in story:
        line_words = line.decode('utf-8').split()
        for word in line_words:
            story_words.append(word)
print(story_words)
Error:
Traceback (most recent call last): File "f_test_area.py", line 3, in <module> with urlopen('http://sixty-north.com/c/t.txt') as story: File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 532, in open response = meth(req, response) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 642, in http_resp File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 532, in open response = meth(req, response) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 642, in http_response 'http', request, response, code, msg, hdrs) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 570, in error return self._call_chain(*args) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 504, in _call_chain result = func(*args) File "C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\urllib\request.py", line 650, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp)urllib.error.HTTPError: HTTP Error 407: authenticationrequired
It seems you connect to the Internet via a proxy server. Your browser is set to work with the proxy but your program is not.
Yes True, we use proxy like every company does.
I'm able to open the URL via any web browser without asking for credentials but not through the Python code.
Is there any way to get this working by passing my default credentials explicitly?

Sorry, i was out of connection for a week hence delay in response.