urllib3 on python 2.7 SNI error on Google App Engine
Asked Answered
V

1

5

I'm trying to download an HTTPS page from my site hosted on Google App Engine with SNI. No matter what library I use, I get the following error:

[Errno 8] _ssl.c:504: EOF occurred in violation of protocol

I've tried solving the error in many ways, including using the urllib3 openssl monkeypatch:

from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3

But I always get the same error mentioned above.

Any ideas?

Veilleux answered 20/10, 2013 at 12:16 Comment(2)
Not sure if this is a typo in your question, but the line should be pyopenssl.inject_into_urllib3() — that is, it's a function call, not a property access.Lockwood
You are completely right! my stupid mistake.. tested and worked, thanks :)Veilleux
L
9

Unfortunately for urllib3, the Python standard library did not add SNI support until Python 3.2. (See Issue #118 @ urllib3)

To use SNI in Python 2.7 with urllib3, you'll need to use the PyOpenSSL injection monkeypatch. (See Issue #156 @ urllib3)

from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()

Your question basically had the same code, except it was missing the parentheses call on the pyopenssl.inject_into_urllib3() call. Fixing that should do the trick.

You'll also need to make sure to have the following dependencies available:

  • pyOpenSSL (tested with 0.13)
  • ndg-httpsclient (tested with 0.3.2)
  • pyasn1 (tested with 0.1.6)
Lockwood answered 20/10, 2013 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.