Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2.7.6: _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure> #15

Closed
sanderjo opened this issue Jan 3, 2017 · 8 comments
Assignees

Comments

@sanderjo
Copy link

sanderjo commented Jan 3, 2017

FYI / FWIW:

On Ubuntu 14.04.5 LTS (with Python 2.7.6) the example.py does not work. See below.

The error

urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>

is a common problem with older python versions in combination with TLS and possibly SNI (Server Name Indication). So far I have not found a solution or workaround within python 2.7.6.
With python 2.7.11 it works fine.

It's easy to reproduce with three lines of code:

$ python
Python 2.7.6 (default, Oct 26 2016, 20:32:47)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> req = urllib2.Request("https://postcode-api.apiwise.nl/")
>>> resp = urllib2.urlopen(req)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>

Output of example.py with Python 2.7.6:

sander@haring:~/postcode-API/git_postcodeapi$ python example.py
ERROR:root:<urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
  File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 99, in getaddress
    data = self.request(path)
  File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 65, in request
    self.url + path, headers=headers,
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
ERROR:root:<urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
  File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 99, in getaddress
    data = self.request(path)
  File "/home/sander/postcode-API/git_postcodeapi/pyPostcode/__init__.py", line 65, in request
    self.url + path, headers=headers,
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>
Traceback (most recent call last):
  File "example.py", line 7, in <module>
    print result.street
AttributeError: 'bool' object has no attribute 'street'

With python 2.7.11 it works fine:

sander@haring:~/postcode-API/git_postcodeapi$ /opt/python2711/bin/python example.py
De Ruijterkade
125
1011AC
Amsterdam
Amsterdam
Noord-Holland
52.3776421
4.9066958
122281
487861
De Ruijterkade
154
1011AC
Amsterdam
Amsterdam
Noord-Holland
52.3772667
4.9094314
122467
487818
@steffex
Copy link
Owner

steffex commented Jan 3, 2017

I've tested it with 2.7.10, this version also seems to work fine.
I'll try to find a workaround for this issue.

@sanderjo It looks like the issue is part of the ssl module shipped with 2.7.6.
I think that there is no other option than to upgrade your python to 2.7.1X

@steffex steffex self-assigned this Jan 3, 2017
@sanderjo
Copy link
Author

sanderjo commented Jan 3, 2017

I've tested it with 2.7.10, this version also seems to work fine.

Yes, python 2.7.9+ works: "Python3 and Python 2.7.9+ include native support for SNI in their SSL modules."

I think that there is no other option than to upgrade your python to 2.7.1X

I think so too. Maybe mention it as requirement in the documentation? And build in a try/except on this specific error message?

@ChintanModi
Copy link

Hello.
First of all, Thank You. This is very helpful.

I am using this with ODOO10 and i don't know how i can get address for P4 format postcode.

i tried entering P4 format post code and house number but no luck.

Thank You in anticipation for guidance.

@steffex
Copy link
Owner

steffex commented Jul 20, 2017

@ChintanModi just use the getaddress method and leave out the housenumber.

for examle:

#!/usr/bin/python

from pyPostcode import Api

postcodeapi = Api('{YOUR_API_KEY}') # Set your own API-key
result = postcodeapi.getaddress('1011AC')
print result.street, result.town

@ChintanModi
Copy link

@steffex , yes i tried that but what i want is say for example postcode is 7766 and if i put this in
getaddress this won't work.

from pyPostcode import Api

postcodeapi = Api('{YOUR_API_KEY}') # Set your own API-key
result = postcodeapi.getaddress('7766')

for this it will show me wrong query parameter error.

@sanderjo
Copy link
Author

yes i tried that but what i want is say for example postcode is 7766 and if i put this in
getaddress this won't work.

"7766" is not a Dutch postcode. A valid Dutch postcode is "7766AA": alway 4 numbers + 2 letters.

@ChintanModi
Copy link

@sanderjo Okay. i got it now. i searched postcode to try with the getaddress and i found 7766 only so i tried this and it was a wrong postcode. i guess i will always have postcode in the format like the one you said.

Thank You. @sanderjo and @steffex .

@sanderjo
Copy link
Author

I will close this. I don't know whether it's solved or not. If not solved, just use python 2.7.9 or higher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants