Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Please don't mark the question as a duplicate. I have gone through every possibility, but I didn't find an answer. I use Ubuntu 12.04(LTS)

Python urlopen function raises this error message when an https site is given as input:

Traceback (most recent call last):
  File "", line 13, in <module>
    htmlfile = urllib.urlopen(url)
  File "/usr/lib/python2.7/", line 86, in urlopen
  File "/usr/lib/python2.7/", line 207, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/", line 436, in open_https
  File "/usr/lib/python2.7/", line 954, in endheaders
  File "/usr/lib/python2.7/", line 814, in _send_output
  File "/usr/lib/python2.7/", line 776, in send
  File "/usr/lib/python2.7/", line 1161, in connect
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "/usr/lib/python2.7/", line 381, in wrap_socket
  File "/usr/lib/python2.7/", line 143, in __init__
  File "/usr/lib/python2.7/", line 305, in do_handshake
IOError: [Errno socket error] [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

How do I fix this?

share|improve this question

marked as duplicate by fossfreedom Feb 24 '14 at 23:46

This question was marked as an exact duplicate of an existing question.

What is the URL? Can you add a small example test file to your question showing this? – fossfreedom Feb 23 '14 at 15:12
" " That is the url – gowtham nanda Feb 23 '14 at 16:19
Ok, Problem solved... Just use urllib2 instead of urllib – gowtham nanda Feb 24 '14 at 11:31

You didn't give your url, so I tried this site.

import sys
import urllib

print sys.version

2.7.5+ (default, Sep 19 2013, 13:48:49)

[GCC 4.8.1]

print urllib.__version__


url = ''
res = urllib.urlopen(url)

print res.url

print res.headers
Cache-Control: public, max-age=60
Content-Type: text/html; charset=utf-8
Expires: Sun, 23 Feb 2014 15:01:28 GMT
Last-Modified: Sun, 23 Feb 2014 15:00:28 GMT
Vary: *
X-Frame-Options: SAMEORIGIN
Date: Sun, 23 Feb 2014 15:00:28 GMT
Connection: close
Content-Length: 70580

At least on Ubuntu 13.10 I can't reproduce the problem.

share|improve this answer
I use Ubuntu 12.04 – gowtham nanda Feb 23 '14 at 16:32
Ok, I treid it in 13.10, still there is an error "IOError: ('http protocol error', 0, 'got a bad status line', None)" – gowtham nanda Feb 24 '14 at 11:21
Ok, Problem solved... Just use urllib2 instead of urllib – gowtham nanda Feb 24 '14 at 11:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.