Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 "fb.py", line 13, in <module>
    htmlfile = urllib.urlopen(url)
  File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 436, in open_https
    h.endheaders(data)
  File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 776, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 1161, in connect
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 143, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
    self._sslobj.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 at 23:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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__

1.17

url = 'https://askubuntu.com'
res = urllib.urlopen(url)

print res.url

https://askubuntu.com/

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 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 at 11:21
    
Ok, Problem solved... Just use urllib2 instead of urllib –  gowtham nanda Feb 24 at 11:32
add comment

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